Coverage Report

Created: 2026-05-30 06:06

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
167k
static inline unsigned read_golomb(MsacContext *const msac) {
50
167k
    int len = 0;
51
167k
    unsigned val = 1;
52
53
299k
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
299k
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
167k
    return val - 1;
57
167k
}
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
1.62M
{
66
1.62M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
1.62M
    if (chroma) {
69
829k
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
829k
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
829k
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
471k
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
829k
        unsigned ca, cl;
74
75
829k
#define MERGE_CTX(dir, type, no_val) \
76
1.65M
        c##dir = *(const type *) dir != no_val; \
77
1.65M
        break
78
79
829k
        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
408k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
146k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
121k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
152k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
829k
        }
91
829k
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
456k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
142k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
90.4k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
140k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
829k
        }
98
829k
#undef MERGE_CTX
99
100
829k
        return 7 + not_one_blk * 3 + ca + cl;
101
829k
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
235k
        return 0;
103
559k
    } else {
104
559k
        unsigned la, ll;
105
106
559k
#define MERGE_CTX(dir, type, tx) \
107
1.12M
        if (tx == TX_64X64) { \
108
32.2k
            uint64_t tmp = *(const uint64_t *) dir; \
109
32.2k
            tmp |= *(const uint64_t *) &dir[8]; \
110
32.2k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
32.2k
        } else \
112
1.12M
            l##dir = *(const type *) dir; \
113
1.12M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
1.12M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
1.12M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
1.12M
        break
117
118
559k
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
407k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
82.7k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
48.1k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
6.00k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
16.1k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
559k
        }
126
560k
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
409k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
81.0k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
48.1k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
6.01k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
16.1k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
560k
        }
134
560k
#undef MERGE_CTX
135
136
560k
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
560k
    }
138
1.62M
}
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
767k
{
144
767k
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
767k
    int s;
146
147
767k
#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
767k
    __asm__("" : "+r"(mask), "+r"(mul));
151
767k
#endif
152
153
767k
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
473k
    case TX_4X4: {
156
473k
        int t = *(const uint8_t *) a >> 6;
157
473k
        t    += *(const uint8_t *) l >> 6;
158
473k
        s = t - 1 - 1;
159
473k
        break;
160
0
    }
161
52.4k
    case TX_8X8: {
162
52.4k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
52.4k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
52.4k
        t *= 0x04040404U;
165
52.4k
        s = (int) (t >> 24) - 2 - 2;
166
52.4k
        break;
167
0
    }
168
29.9k
    case TX_16X16: {
169
29.9k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
29.9k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
29.9k
        t *= (uint32_t) mul;
172
29.9k
        s = (int) (t >> 24) - 4 - 4;
173
29.9k
        break;
174
0
    }
175
25.9k
    case TX_32X32: {
176
25.9k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
25.9k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
25.9k
        t *= mul;
179
25.9k
        s = (int) (t >> 56) - 8 - 8;
180
25.9k
        break;
181
0
    }
182
10.0k
    case TX_64X64: {
183
10.0k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
10.0k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
10.0k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
10.0k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
10.0k
        t *= mul;
188
10.0k
        s = (int) (t >> 56) - 16 - 16;
189
10.0k
        break;
190
0
    }
191
16.4k
    case RTX_4X8: {
192
16.4k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
16.4k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
16.4k
        t *= 0x04040404U;
195
16.4k
        s = (int) (t >> 24) - 1 - 2;
196
16.4k
        break;
197
0
    }
198
28.4k
    case RTX_8X4: {
199
28.4k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
28.4k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
28.4k
        t *= 0x04040404U;
202
28.4k
        s = (int) (t >> 24) - 2 - 1;
203
28.4k
        break;
204
0
    }
205
15.2k
    case RTX_8X16: {
206
15.2k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
15.2k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
15.2k
        t = (t >> 6) * (uint32_t) mul;
209
15.2k
        s = (int) (t >> 24) - 2 - 4;
210
15.2k
        break;
211
0
    }
212
35.4k
    case RTX_16X8: {
213
35.4k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
35.4k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
35.4k
        t = (t >> 6) * (uint32_t) mul;
216
35.4k
        s = (int) (t >> 24) - 4 - 2;
217
35.4k
        break;
218
0
    }
219
16.1k
    case RTX_16X32: {
220
16.1k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
16.1k
        t         += *(const uint64_t *) l & mask;
222
16.1k
        t = (t >> 6) * mul;
223
16.1k
        s = (int) (t >> 56) - 4 - 8;
224
16.1k
        break;
225
0
    }
226
22.8k
    case RTX_32X16: {
227
22.8k
        uint64_t t = *(const uint64_t *) a & mask;
228
22.8k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
22.8k
        t = (t >> 6) * mul;
230
22.8k
        s = (int) (t >> 56) - 8 - 4;
231
22.8k
        break;
232
0
    }
233
10.5k
    case RTX_32X64: {
234
10.5k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
10.5k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
10.5k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
10.5k
        t *= mul;
238
10.5k
        s = (int) (t >> 56) - 8 - 16;
239
10.5k
        break;
240
0
    }
241
8.50k
    case RTX_64X32: {
242
8.50k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
8.50k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
8.50k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
8.50k
        t *= mul;
246
8.50k
        s = (int) (t >> 56) - 16 - 8;
247
8.50k
        break;
248
0
    }
249
4.80k
    case RTX_4X16: {
250
4.80k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
4.80k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
4.80k
        t = (t >> 6) * (uint32_t) mul;
253
4.80k
        s = (int) (t >> 24) - 1 - 4;
254
4.80k
        break;
255
0
    }
256
9.19k
    case RTX_16X4: {
257
9.19k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
9.19k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
9.19k
        t = (t >> 6) * (uint32_t) mul;
260
9.19k
        s = (int) (t >> 24) - 4 - 1;
261
9.19k
        break;
262
0
    }
263
2.83k
    case RTX_8X32: {
264
2.83k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
2.83k
        t         += *(const uint64_t *) l & mask;
266
2.83k
        t = (t >> 6) * mul;
267
2.83k
        s = (int) (t >> 56) - 2 - 8;
268
2.83k
        break;
269
0
    }
270
4.21k
    case RTX_32X8: {
271
4.21k
        uint64_t t = *(const uint64_t *) a & mask;
272
4.21k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
4.21k
        t = (t >> 6) * mul;
274
4.21k
        s = (int) (t >> 56) - 8 - 2;
275
4.21k
        break;
276
0
    }
277
671
    case RTX_16X64: {
278
671
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
671
        t         += *(const uint64_t *) &l[0] & mask;
280
671
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
671
        t *= mul;
282
671
        s = (int) (t >> 56) - 4 - 16;
283
671
        break;
284
0
    }
285
535
    case RTX_64X16: {
286
535
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
535
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
535
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
535
        t *= mul;
290
535
        s = (int) (t >> 56) - 16 - 4;
291
535
        break;
292
0
    }
293
767k
    }
294
295
767k
    return (s != 0) + (s > 0);
296
767k
}
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
11.3M
{
305
11.3M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
11.3M
    unsigned offset;
307
11.3M
    if (tx_class == TX_CLASS_2D) {
308
10.7M
        mag += levels[1 * stride + 1];
309
10.7M
        *hi_mag = mag;
310
10.7M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
10.7M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
10.7M
    } else {
313
618k
        mag += levels[0 * stride + 2];
314
618k
        *hi_mag = mag;
315
618k
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
618k
        offset = 26 + (y > 1 ? 10 : y * 5);
317
618k
    }
318
11.3M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
11.3M
}
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
1.62M
{
328
1.62M
    Dav1dTileState *const ts = t->ts;
329
1.62M
    const int chroma = !!plane;
330
1.62M
    const Dav1dFrameContext *const f = t->f;
331
1.62M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
1.62M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
1.62M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
1.62M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
1.62M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
1.62M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
1.62M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
1.62M
    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
1.62M
    if (all_skip) {
346
739k
        *res_ctx = 0x40;
347
739k
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
739k
        return -1;
349
739k
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
885k
    if (lossless) {
353
463k
        assert(t_dim->max == TX_4X4);
354
463k
        *txtp = WHT_WHT;
355
463k
    } else if (t_dim->max + intra >= TX_64X64) {
356
101k
        *txtp = DCT_DCT;
357
320k
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
77.7k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
77.7k
                        get_uv_inter_txtp(t_dim, *txtp);
361
243k
    } 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
3.26k
        *txtp = DCT_DCT;
366
239k
    } else {
367
239k
        unsigned idx;
368
239k
        if (intra) {
369
182k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
158k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
182k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
60.7k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
60.7k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
60.7k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
121k
            } else {
376
121k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
121k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
121k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
121k
            }
380
182k
            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
182k
        } else {
384
57.5k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
18.4k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
18.4k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
18.4k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
39.1k
            } else if (t_dim->min == TX_16X16) {
389
4.05k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
4.05k
                          ts->cdf.m.txtp_inter2, 11);
391
4.05k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
35.0k
            } else {
393
35.0k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
35.0k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
35.0k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
35.0k
            }
397
57.5k
            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
57.5k
        }
401
239k
    }
402
403
    // find end-of-block (eob)
404
885k
    int eob;
405
885k
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
885k
    const int tx2dszctx = slw + slh;
407
885k
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
885k
    const int is_1d = tx_class != TX_CLASS_2D;
409
885k
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
886k
    case sz: { \
412
886k
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
886k
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
886k
        break; \
415
886k
    }
416
525k
    case_sz(0,   16,  8, [is_1d]);
417
58.6k
    case_sz(1,   32,  8, [is_1d]);
418
85.1k
    case_sz(2,   64,  8, [is_1d]);
419
65.6k
    case_sz(3,  128,  8, [is_1d]);
420
46.1k
    case_sz(4,  256, 16, [is_1d]);
421
45.4k
    case_sz(5,  512, 16,        );
422
59.3k
    case_sz(6, 1024, 16,        );
423
885k
#undef case_sz
424
885k
    }
425
886k
    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
886k
    if (eob > 1) {
429
517k
        const int eob_bin = eob - 2;
430
517k
        uint16_t *const eob_hi_bit_cdf =
431
517k
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
517k
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
517k
        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
517k
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
517k
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
517k
    }
440
886k
    assert(eob >= 0);
441
442
    // base tokens
443
886k
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
886k
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
886k
    unsigned rc, dc_tok;
446
447
886k
    if (eob) {
448
544k
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
544k
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
544k
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
544k
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
544k
        int tok = eob_tok + 1;
455
544k
        int level_tok = tok * 0x41;
456
544k
        unsigned mag;
457
458
544k
#define DECODE_COEFS_CLASS(tx_class) \
459
544k
        unsigned x, y; \
460
544k
        uint8_t *level; \
461
544k
        if (tx_class == TX_CLASS_2D) \
462
544k
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
544k
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
33.6k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
33.6k
        else /* tx_class == TX_CLASS_V */ \
467
33.6k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
544k
        if (dbg) \
469
544k
            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
544k
        if (eob_tok == 2) { \
472
22.8k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
22.8k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
22.8k
            level_tok = tok + (3 << 6); \
475
22.8k
            if (dbg) \
476
22.8k
                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
22.8k
        } \
480
544k
        cf[rc] = tok << 11; \
481
544k
        if (tx_class == TX_CLASS_2D) \
482
544k
            level = levels + rc; \
483
544k
        else \
484
544k
            level = levels + x * stride + y; \
485
544k
        *level = (uint8_t) level_tok; \
486
11.8M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
11.2M
            unsigned rc_i; \
488
11.2M
            if (tx_class == TX_CLASS_2D) \
489
11.2M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
11.2M
            else if (tx_class == TX_CLASS_H) \
491
592k
                x = i & mask, y = i >> shift, rc_i = i; \
492
592k
            else /* tx_class == TX_CLASS_V */ \
493
592k
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
11.2M
            assert(x < 32 && y < 32); \
495
11.2M
            if (tx_class == TX_CLASS_2D) \
496
11.2M
                level = levels + rc_i; \
497
11.2M
            else \
498
11.2M
                level = levels + x * stride + y; \
499
11.2M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
11.2M
            if (tx_class == TX_CLASS_2D) \
501
11.2M
                y |= x; \
502
11.2M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
11.2M
            if (dbg) \
504
11.2M
                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
11.2M
            if (tok == 3) { \
507
1.05M
                mag &= 63; \
508
1.05M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
1.05M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
1.05M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
1.05M
                if (dbg) \
512
1.05M
                    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
1.05M
                *level = (uint8_t) (tok + (3 << 6)); \
516
1.05M
                cf[rc_i] = (tok << 11) | rc; \
517
1.05M
                rc = rc_i; \
518
10.2M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
10.2M
                tok *= 0x17ff41; \
521
10.2M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
10.2M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
10.2M
                if (tok) rc = rc_i; \
525
10.2M
                cf[rc_i] = tok; \
526
10.2M
            } \
527
11.2M
        } \
528
        /* dc */ \
529
544k
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
544k
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
544k
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
544k
        if (dbg) \
533
544k
            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
544k
        if (dc_tok == 3) { \
536
224k
            if (tx_class == TX_CLASS_2D) \
537
224k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
220k
                      levels[1 * stride + 1]; \
539
224k
            mag &= 63; \
540
224k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
224k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
224k
            if (dbg) \
543
224k
                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
224k
        } \
546
544k
        break
547
548
544k
        const uint16_t *scan;
549
544k
        switch (tx_class) {
550
511k
        case TX_CLASS_2D: {
551
511k
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
511k
            const uint8_t (*const lo_ctx_offsets)[5] =
553
511k
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
511k
            scan = dav1d_scans[tx];
555
511k
            const ptrdiff_t stride = 4 << slh;
556
511k
            const unsigned shift = slh + 2, shift2 = 0;
557
511k
            const unsigned mask = (4 << slh) - 1;
558
511k
            memset(levels, 0, stride * ((4 << slw) + 2));
559
511k
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
511k
        }
561
21.7k
        case TX_CLASS_H: {
562
21.7k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
21.7k
            const ptrdiff_t stride = 16;
564
21.7k
            const unsigned shift = slh + 2, shift2 = 0;
565
21.7k
            const unsigned mask = (4 << slh) - 1;
566
21.7k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
21.7k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
21.7k
        }
569
11.9k
        case TX_CLASS_V: {
570
11.9k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
11.9k
            const ptrdiff_t stride = 16;
572
11.9k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
11.9k
            const unsigned mask = (4 << slw) - 1;
574
11.9k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
11.9k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
11.9k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
544k
        }
580
544k
    } else { // dc-only
581
341k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
341k
        dc_tok = 1 + tok_br;
583
341k
        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
341k
        if (tok_br == 2) {
587
10.2k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
10.2k
            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
10.2k
        }
592
341k
        rc = 0;
593
341k
    }
594
595
    // residual and sign
596
885k
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
885k
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
885k
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
885k
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
885k
    unsigned cul_level, dc_sign_level;
601
602
885k
    if (!dc_tok) {
603
119k
        cul_level = 0;
604
119k
        dc_sign_level = 1 << 6;
605
119k
        if (qm_tbl) goto ac_qm;
606
102k
        goto ac_noqm;
607
119k
    }
608
609
766k
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
766k
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
766k
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
766k
    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
766k
    int dc_dq = dq_tbl[0];
617
766k
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
766k
    if (qm_tbl) {
620
92.0k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
92.0k
        if (dc_tok == 15) {
623
4.47k
            dc_tok = read_golomb(&ts->msac) + 15;
624
4.47k
            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
4.47k
            dc_tok &= 0xfffff;
629
4.47k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
87.5k
        } else {
631
87.5k
            dc_dq *= dc_tok;
632
87.5k
            assert(dc_dq <= 0xffffff);
633
87.5k
        }
634
92.0k
        cul_level = dc_tok;
635
92.0k
        dc_dq >>= dq_shift;
636
92.0k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
92.0k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
139k
        if (rc) ac_qm: {
640
139k
            const unsigned ac_dq = dq_tbl[1];
641
1.10M
            do {
642
1.10M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
1.10M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
1.10M
                const unsigned rc_tok = cf[rc];
646
1.10M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
1.10M
                int dq_sat;
648
649
1.10M
                if (rc_tok >= (15 << 11)) {
650
32.4k
                    tok = read_golomb(&ts->msac) + 15;
651
32.4k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
32.4k
                    tok &= 0xfffff;
656
32.4k
                    dq = (dq * tok) & 0xffffff;
657
1.07M
                } else {
658
1.07M
                    tok = rc_tok >> 11;
659
1.07M
                    dq *= tok;
660
1.07M
                    assert(dq <= 0xffffff);
661
1.07M
                }
662
1.10M
                cul_level += tok;
663
1.10M
                dq >>= dq_shift;
664
1.10M
                dq_sat = umin(dq, cf_max + sign);
665
1.10M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
1.10M
                rc = rc_tok & 0x3ff;
668
1.10M
            } while (rc);
669
139k
        }
670
674k
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
674k
        if (dc_tok == 15) {
673
26.8k
            dc_tok = read_golomb(&ts->msac) + 15;
674
26.8k
            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
26.8k
            dc_tok &= 0xfffff;
679
26.8k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
26.8k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
647k
        } else {
682
647k
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
647k
            assert(dc_dq <= cf_max);
684
647k
        }
685
674k
        cul_level = dc_tok;
686
674k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
831k
        if (rc) ac_noqm: {
689
831k
            const unsigned ac_dq = dq_tbl[1];
690
3.82M
            do {
691
3.82M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
3.82M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
3.82M
                const unsigned rc_tok = cf[rc];
695
3.82M
                unsigned tok;
696
3.82M
                int dq;
697
698
                // residual
699
3.82M
                if (rc_tok >= (15 << 11)) {
700
103k
                    tok = read_golomb(&ts->msac) + 15;
701
103k
                    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
103k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
103k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
103k
                    dq = umin(dq, cf_max + sign);
711
3.71M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
3.71M
                    tok = rc_tok >> 11;
714
3.71M
                    dq = ((ac_dq * tok) >> dq_shift);
715
3.71M
                    assert(dq <= cf_max);
716
3.71M
                }
717
3.82M
                cul_level += tok;
718
3.82M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
3.82M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
3.82M
            } while (rc);
722
831k
        }
723
674k
    }
724
725
    // context
726
885k
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
885k
    return eob;
729
766k
}
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
282k
{
737
282k
    const Dav1dFrameContext *const f = t->f;
738
282k
    Dav1dTileState *const ts = t->ts;
739
282k
    const Dav1dDSPContext *const dsp = f->dsp;
740
282k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
282k
    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
282k
    if (depth < 2 && tx_split[depth] &&
746
17.0k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
13.3k
    {
748
13.3k
        const enum RectTxfmSize sub = t_dim->sub;
749
13.3k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
13.3k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
13.3k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
13.3k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
13.3k
        t->bx += txsw;
755
13.3k
        if (txw >= txh && t->bx < f->bw)
756
9.68k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
9.68k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
13.3k
        t->bx -= txsw;
759
13.3k
        t->by += txsh;
760
13.3k
        if (txh >= txw && t->by < f->bh) {
761
9.10k
            if (dst)
762
1.67k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
9.10k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
9.10k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
9.10k
            t->bx += txsw;
766
9.10k
            if (txw >= txh && t->bx < f->bw)
767
5.47k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
5.47k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
9.10k
            t->bx -= txsw;
770
9.10k
        }
771
13.3k
        t->by -= txsh;
772
269k
    } else {
773
269k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
269k
        enum TxfmType txtp;
775
269k
        uint8_t cf_ctx;
776
269k
        int eob;
777
269k
        coef *cf;
778
779
269k
        if (t->frame_thread.pass) {
780
269k
            const int p = t->frame_thread.pass & 1;
781
269k
            assert(ts->frame_thread[p].cf);
782
269k
            cf = ts->frame_thread[p].cf;
783
269k
            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
784
18.4E
        } else {
785
18.4E
            cf = bitfn(t->cf);
786
18.4E
        }
787
269k
        if (t->frame_thread.pass != 2) {
788
234k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
234k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
234k
            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
234k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
234k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
234k
#define set_ctx(rep_macro) \
796
637k
            for (int y = 0; y < txh; y++) { \
797
402k
                rep_macro(txtp_map, 0, txtp); \
798
402k
                txtp_map += 32; \
799
402k
            }
800
234k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
234k
            case_set_upto16(t_dim->lw);
802
234k
#undef set_ctx
803
234k
            if (t->frame_thread.pass == 1)
804
234k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
234k
        } else {
806
35.1k
            const int cbi = *ts->frame_thread[0].cbi++;
807
35.1k
            eob  = cbi >> 5;
808
35.1k
            txtp = cbi & 0x1f;
809
35.1k
        }
810
269k
        if (!(t->frame_thread.pass & 1)) {
811
35.1k
            assert(dst);
812
35.1k
            if (eob >= 0) {
813
26.9k
                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
26.9k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
26.9k
                                              HIGHBD_CALL_SUFFIX);
817
26.9k
                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
26.9k
            }
820
35.1k
        }
821
269k
    }
822
282k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
831k
{
827
831k
    const Dav1dFrameContext *const f = t->f;
828
831k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
831k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
831k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
831k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
831k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
831k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
831k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
831k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
743k
                           (bw4 > ss_hor || t->bx & 1) &&
837
646k
                           (bh4 > ss_ver || t->by & 1);
838
839
831k
    if (b->skip) {
840
523k
        BlockContext *const a = t->a;
841
523k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
523k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
523k
        if (has_chroma) {
844
345k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
345k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
345k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
345k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
345k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
345k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
345k
        }
851
523k
        return;
852
523k
    }
853
854
308k
    Dav1dTileState *const ts = t->ts;
855
308k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
308k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
308k
    assert(t->frame_thread.pass == 1);
858
308k
    assert(!b->skip);
859
308k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
308k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
308k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
623k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
315k
        const int sub_h4 = imin(h4, 16 + init_y);
865
636k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
320k
            const int sub_w4 = imin(w4, init_x + 16);
867
320k
            int y_off = !!init_y, y, x;
868
732k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
412k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
412k
            {
871
412k
                int x_off = !!init_x;
872
1.18M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
776k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
776k
                {
875
776k
                    if (!b->intra) {
876
213k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
213k
                                       x_off, y_off, NULL);
878
562k
                    } else {
879
562k
                        uint8_t cf_ctx = 0x40;
880
562k
                        enum TxfmType txtp;
881
562k
                        const int eob =
882
562k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
562k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
562k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
562k
                        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
562k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
562k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
562k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
562k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
562k
                    }
893
776k
                }
894
412k
                t->bx -= x;
895
412k
            }
896
320k
            t->by -= y;
897
898
320k
            if (!has_chroma) continue;
899
900
256k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
256k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
769k
            for (int pl = 0; pl < 2; pl++) {
903
1.11M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
604k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
604k
                {
906
1.43M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
829k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
829k
                    {
909
829k
                        uint8_t cf_ctx = 0x40;
910
829k
                        enum TxfmType txtp;
911
829k
                        if (!b->intra)
912
197k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
197k
                                                        bx4 + (x << ss_hor)];
914
829k
                        const int eob =
915
829k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
829k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
829k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
829k
                                         &txtp, &cf_ctx);
919
829k
                        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
829k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
829k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
829k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
829k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
829k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
829k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
829k
                    }
930
604k
                    t->bx -= x << ss_hor;
931
604k
                }
932
513k
                t->by -= y << ss_ver;
933
513k
            }
934
256k
        }
935
315k
    }
936
308k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
429k
{
827
429k
    const Dav1dFrameContext *const f = t->f;
828
429k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
429k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
429k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
429k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
429k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
429k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
429k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
429k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
394k
                           (bw4 > ss_hor || t->bx & 1) &&
837
343k
                           (bh4 > ss_ver || t->by & 1);
838
839
429k
    if (b->skip) {
840
274k
        BlockContext *const a = t->a;
841
274k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
274k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
274k
        if (has_chroma) {
844
185k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
185k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
185k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
185k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
185k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
185k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
185k
        }
851
274k
        return;
852
274k
    }
853
854
155k
    Dav1dTileState *const ts = t->ts;
855
155k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
155k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
155k
    assert(t->frame_thread.pass == 1);
858
155k
    assert(!b->skip);
859
155k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
155k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
155k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
314k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
158k
        const int sub_h4 = imin(h4, 16 + init_y);
865
320k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
161k
            const int sub_w4 = imin(w4, init_x + 16);
867
161k
            int y_off = !!init_y, y, x;
868
380k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
218k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
218k
            {
871
218k
                int x_off = !!init_x;
872
666k
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
448k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
448k
                {
875
448k
                    if (!b->intra) {
876
146k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
146k
                                       x_off, y_off, NULL);
878
301k
                    } else {
879
301k
                        uint8_t cf_ctx = 0x40;
880
301k
                        enum TxfmType txtp;
881
301k
                        const int eob =
882
301k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
301k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
301k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
301k
                        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
301k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
301k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
301k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
301k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
301k
                    }
893
448k
                }
894
218k
                t->bx -= x;
895
218k
            }
896
161k
            t->by -= y;
897
898
161k
            if (!has_chroma) continue;
899
900
134k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
134k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
404k
            for (int pl = 0; pl < 2; pl++) {
903
599k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
330k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
330k
                {
906
795k
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
465k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
465k
                    {
909
465k
                        uint8_t cf_ctx = 0x40;
910
465k
                        enum TxfmType txtp;
911
465k
                        if (!b->intra)
912
118k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
118k
                                                        bx4 + (x << ss_hor)];
914
465k
                        const int eob =
915
465k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
465k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
465k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
465k
                                         &txtp, &cf_ctx);
919
465k
                        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
465k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
465k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
465k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
465k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
465k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
465k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
465k
                    }
930
330k
                    t->bx -= x << ss_hor;
931
330k
                }
932
269k
                t->by -= y << ss_ver;
933
269k
            }
934
134k
        }
935
158k
    }
936
155k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
402k
{
827
402k
    const Dav1dFrameContext *const f = t->f;
828
402k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
402k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
402k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
402k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
402k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
402k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
402k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
402k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
349k
                           (bw4 > ss_hor || t->bx & 1) &&
837
302k
                           (bh4 > ss_ver || t->by & 1);
838
839
402k
    if (b->skip) {
840
249k
        BlockContext *const a = t->a;
841
249k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
249k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
249k
        if (has_chroma) {
844
160k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
160k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
160k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
160k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
160k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
160k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
160k
        }
851
249k
        return;
852
249k
    }
853
854
152k
    Dav1dTileState *const ts = t->ts;
855
152k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
152k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
152k
    assert(t->frame_thread.pass == 1);
858
152k
    assert(!b->skip);
859
152k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
152k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
152k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
309k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
156k
        const int sub_h4 = imin(h4, 16 + init_y);
865
315k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
158k
            const int sub_w4 = imin(w4, init_x + 16);
867
158k
            int y_off = !!init_y, y, x;
868
352k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
193k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
193k
            {
871
193k
                int x_off = !!init_x;
872
521k
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
327k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
327k
                {
875
327k
                    if (!b->intra) {
876
67.2k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
67.2k
                                       x_off, y_off, NULL);
878
260k
                    } else {
879
260k
                        uint8_t cf_ctx = 0x40;
880
260k
                        enum TxfmType txtp;
881
260k
                        const int eob =
882
260k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
260k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
260k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
260k
                        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
260k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
260k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
260k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
260k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
260k
                    }
893
327k
                }
894
193k
                t->bx -= x;
895
193k
            }
896
158k
            t->by -= y;
897
898
158k
            if (!has_chroma) continue;
899
900
121k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
121k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
365k
            for (int pl = 0; pl < 2; pl++) {
903
518k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
274k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
274k
                {
906
638k
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
364k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
364k
                    {
909
364k
                        uint8_t cf_ctx = 0x40;
910
364k
                        enum TxfmType txtp;
911
364k
                        if (!b->intra)
912
78.7k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
78.7k
                                                        bx4 + (x << ss_hor)];
914
364k
                        const int eob =
915
364k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
364k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
364k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
364k
                                         &txtp, &cf_ctx);
919
364k
                        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
364k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
364k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
364k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
364k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
364k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
364k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
364k
                    }
930
274k
                    t->bx -= x << ss_hor;
931
274k
                }
932
243k
                t->by -= y << ss_ver;
933
243k
            }
934
121k
        }
935
156k
    }
936
152k
}
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
235k
{
945
235k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
235k
    const Dav1dFrameContext *const f = t->f;
947
235k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
235k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
235k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
235k
    const int mvx = mv.x, mvy = mv.y;
951
235k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
235k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
235k
    const pixel *ref;
954
955
235k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
215k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
215k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
215k
        int w, h;
959
960
215k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
72.3k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
72.3k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
143k
        } else {
964
143k
            w = f->bw * 4 >> ss_hor;
965
143k
            h = f->bh * 4 >> ss_ver;
966
143k
        }
967
215k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
203k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
178k
            dy + bh4 * v_mul + !!my * 4 > h)
970
61.3k
        {
971
61.3k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
61.3k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
61.3k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
61.3k
                                emu_edge_buf, 192 * sizeof(pixel),
975
61.3k
                                refp->p.data[pl], ref_stride);
976
61.3k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
61.3k
            ref_stride = 192 * sizeof(pixel);
978
154k
        } else {
979
154k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
154k
        }
981
982
215k
        if (dst8 != NULL) {
983
203k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
203k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
203k
                                     HIGHBD_CALL_SUFFIX);
986
203k
        } else {
987
12.6k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
12.6k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
12.6k
                                      HIGHBD_CALL_SUFFIX);
990
12.6k
        }
991
215k
    } else {
992
19.8k
        assert(refp != &f->sr_cur);
993
994
19.8k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
19.8k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
39.6k
#define scale_mv(res, val, scale) do { \
997
39.6k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
39.6k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
39.6k
        } while (0)
1000
19.8k
        int pos_y, pos_x;
1001
19.8k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
19.8k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
19.8k
#undef scale_mv
1004
19.8k
        const int left = pos_x >> 10;
1005
19.8k
        const int top = pos_y >> 10;
1006
19.8k
        const int right =
1007
19.8k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
19.8k
        const int bottom =
1009
19.8k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
19.8k
        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
19.8k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
19.8k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
19.8k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
16.3k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
16.3k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
16.3k
                                w, h, left - 3, top - 3,
1023
16.3k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
16.3k
                                refp->p.data[pl], ref_stride);
1025
16.3k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
16.3k
            ref_stride = 320 * sizeof(pixel);
1027
16.3k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
16.3k
        } else {
1029
3.49k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
3.49k
        }
1031
1032
19.8k
        if (dst8 != NULL) {
1033
13.9k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
13.9k
                                            bw4 * h_mul, bh4 * v_mul,
1035
13.9k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
13.9k
                                            f->svc[refidx][0].step,
1037
13.9k
                                            f->svc[refidx][1].step
1038
13.9k
                                            HIGHBD_CALL_SUFFIX);
1039
13.9k
        } else {
1040
5.86k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
5.86k
                                             bw4 * h_mul, bh4 * v_mul,
1042
5.86k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
5.86k
                                             f->svc[refidx][0].step,
1044
5.86k
                                             f->svc[refidx][1].step
1045
5.86k
                                             HIGHBD_CALL_SUFFIX);
1046
5.86k
        }
1047
19.8k
    }
1048
1049
235k
    return 0;
1050
235k
}
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
10.5k
{
1057
10.5k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
10.5k
    const Dav1dFrameContext *const f = t->f;
1059
10.5k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
10.5k
    pixel *const lap = bitfn(t->scratch.lap);
1061
10.5k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
10.5k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
10.5k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
10.5k
    int res;
1065
1066
10.5k
    if (t->by > t->ts->tiling.row_start &&
1067
8.68k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
7.99k
    {
1069
17.0k
        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
9.05k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
9.05k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
9.05k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
9.05k
            if (a_r->ref.ref[0] > 0) {
1076
8.92k
                const int ow4 = imin(step4, b_dim[0]);
1077
8.92k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
8.92k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
8.92k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
8.92k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
8.92k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
8.92k
                if (res) return res;
1083
8.92k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
8.92k
                                   h_mul * ow4, v_mul * oh4);
1085
8.92k
                i++;
1086
8.92k
            }
1087
9.05k
            x += step4;
1088
9.05k
        }
1089
7.99k
    }
1090
1091
10.5k
    if (t->bx > t->ts->tiling.col_start)
1092
19.5k
        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
10.1k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
10.1k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
10.1k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
10.1k
            if (l_r->ref.ref[0] > 0) {
1099
10.0k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
10.0k
                const int oh4 = imin(step4, b_dim[1]);
1101
10.0k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
10.0k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
10.0k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
10.0k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
10.0k
                if (res) return res;
1106
10.0k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
10.0k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
10.0k
                i++;
1109
10.0k
            }
1110
10.1k
            y += step4;
1111
10.1k
        }
1112
10.5k
    return 0;
1113
10.5k
}
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
5.46k
{
1121
5.46k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
5.46k
    const Dav1dFrameContext *const f = t->f;
1123
5.46k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
5.46k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
5.46k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
5.46k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
5.46k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
5.46k
    const int32_t *const mat = wmp->matrix;
1129
5.46k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
5.46k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
19.4k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
13.9k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
13.9k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
13.9k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
77.6k
        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
63.6k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
63.6k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
63.6k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
63.6k
            const int dx = (int) (mvx >> 16) - 4;
1144
63.6k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
63.6k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
63.6k
            const int dy = (int) (mvy >> 16) - 4;
1147
63.6k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
63.6k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
63.6k
            const pixel *ref_ptr;
1151
63.6k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
63.6k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
44.1k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
44.1k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
44.1k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
44.1k
                                    refp->p.data[pl], ref_stride);
1158
44.1k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
44.1k
                ref_stride = 32 * sizeof(pixel);
1160
44.1k
            } else {
1161
19.5k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
19.5k
            }
1163
63.6k
            if (dst16 != NULL)
1164
18.3k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
18.3k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
45.3k
            else
1167
45.3k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
45.3k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
63.6k
        }
1170
13.9k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
2.92k
        else      dst16 += 8 * dstride;
1172
13.9k
    }
1173
5.46k
    return 0;
1174
5.46k
}
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
265k
{
1180
265k
    Dav1dTileState *const ts = t->ts;
1181
265k
    const Dav1dFrameContext *const f = t->f;
1182
265k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
265k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
265k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
265k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
265k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
265k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
265k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
265k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
265k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
265k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
244k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
237k
                           (bh4 > ss_ver || t->by & 1);
1194
265k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
265k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
265k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
265k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
265k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
543k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
278k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
278k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
561k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
283k
            if (b->pal_sz[0]) {
1208
757
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
757
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
757
                const uint8_t *pal_idx;
1211
757
                if (t->frame_thread.pass) {
1212
757
                    const int p = t->frame_thread.pass & 1;
1213
757
                    assert(ts->frame_thread[p].pal_idx);
1214
757
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
757
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
757
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
757
                const pixel *const pal = t->frame_thread.pass ?
1220
757
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
757
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
757
                    bytefn(t->scratch.pal)[0];
1223
757
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
757
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
757
                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
757
            }
1229
1230
283k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
283k
                                     sm_flag(&t->l, by4) |
1232
283k
                                     intra_edge_filter_flag);
1233
283k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
278k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
283k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
278k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
283k
            int y, x;
1238
283k
            const int sub_w4 = imin(w4, init_x + 16);
1239
679k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
395k
                 y += t_dim->h, t->by += t_dim->h)
1241
395k
            {
1242
395k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
395k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
395k
                                    t->bx + init_x);
1245
1.00M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
606k
                     x += t_dim->w, t->bx += t_dim->w)
1247
606k
                {
1248
606k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
605k
                    int angle = b->y_angle;
1251
605k
                    const enum EdgeFlags edge_flags =
1252
605k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
444k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
605k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
331k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
605k
                    const pixel *top_sb_edge = NULL;
1257
605k
                    if (!(t->by & (f->sb_step - 1))) {
1258
171k
                        top_sb_edge = f->ipred_edge[0];
1259
171k
                        const int sby = t->by >> f->sb_shift;
1260
171k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
171k
                    }
1262
605k
                    const enum IntraPredMode m =
1263
605k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
605k
                                                          t->bx > ts->tiling.col_start,
1265
605k
                                                          t->by,
1266
605k
                                                          t->by > ts->tiling.row_start,
1267
605k
                                                          ts->tiling.col_end,
1268
605k
                                                          ts->tiling.row_end,
1269
605k
                                                          edge_flags, dst,
1270
605k
                                                          f->cur.stride[0], top_sb_edge,
1271
605k
                                                          b->y_mode, &angle,
1272
605k
                                                          t_dim->w, t_dim->h,
1273
605k
                                                          f->seq_hdr->intra_edge_filter,
1274
605k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
605k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
605k
                                             t_dim->w * 4, t_dim->h * 4,
1277
605k
                                             angle | intra_flags,
1278
605k
                                             4 * f->bw - 4 * t->bx,
1279
605k
                                             4 * f->bh - 4 * t->by
1280
605k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
605k
                    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
606k
                skip_y_pred: {}
1293
606k
                    if (!b->skip) {
1294
199k
                        coef *cf;
1295
199k
                        int eob;
1296
199k
                        enum TxfmType txtp;
1297
199k
                        if (t->frame_thread.pass) {
1298
199k
                            const int p = t->frame_thread.pass & 1;
1299
199k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
199k
                            cf = ts->frame_thread[p].cf;
1301
199k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
199k
                            eob  = cbi >> 5;
1303
199k
                            txtp = cbi & 0x1f;
1304
199k
                        } 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
199k
                        if (eob >= 0) {
1317
138k
                            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
138k
                            dsp->itx.itxfm_add[b->tx]
1321
138k
                                              [txtp](dst,
1322
138k
                                                     f->cur.stride[0],
1323
138k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
138k
                            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
138k
                        }
1328
407k
                    } 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
606k
                    dst += 4 * t_dim->w;
1333
606k
                }
1334
395k
                t->bx -= x;
1335
395k
            }
1336
283k
            t->by -= y;
1337
1338
283k
            if (!has_chroma) continue;
1339
1340
250k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
250k
            if (b->uv_mode == CFL_PRED) {
1343
95.1k
                assert(!init_x && !init_y);
1344
1345
95.1k
                int16_t *const ac = t->scratch.ac;
1346
95.1k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
95.1k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
95.1k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
95.1k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
95.1k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
95.1k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
95.1k
                const int furthest_r =
1354
95.1k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
95.1k
                const int furthest_b =
1356
95.1k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
95.1k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
95.1k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
95.1k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
95.1k
                                                         cbw4 * 4, cbh4 * 4);
1361
285k
                for (int pl = 0; pl < 2; pl++) {
1362
190k
                    if (!b->cfl_alpha[pl]) continue;
1363
177k
                    int angle = 0;
1364
177k
                    const pixel *top_sb_edge = NULL;
1365
177k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
48.1k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
48.1k
                        const int sby = t->by >> f->sb_shift;
1368
48.1k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
48.1k
                    }
1370
177k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
177k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
177k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
177k
                    const enum IntraPredMode m =
1374
177k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
177k
                                                          ypos, ypos > ystart,
1376
177k
                                                          ts->tiling.col_end >> ss_hor,
1377
177k
                                                          ts->tiling.row_end >> ss_ver,
1378
177k
                                                          0, uv_dst[pl], stride,
1379
177k
                                                          top_sb_edge, DC_PRED, &angle,
1380
177k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
177k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
177k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
177k
                                           uv_t_dim->w * 4,
1384
177k
                                           uv_t_dim->h * 4,
1385
177k
                                           ac, b->cfl_alpha[pl]
1386
177k
                                           HIGHBD_CALL_SUFFIX);
1387
177k
                }
1388
95.1k
                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
154k
            } else if (b->pal_sz[1]) {
1394
451
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
451
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
451
                const pixel (*pal)[8];
1397
451
                const uint8_t *pal_idx;
1398
451
                if (t->frame_thread.pass) {
1399
451
                    const int p = t->frame_thread.pass & 1;
1400
451
                    assert(ts->frame_thread[p].pal_idx);
1401
451
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
451
                                              ((t->bx >> 1) + (t->by & 1))];
1403
451
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
451
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
451
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
451
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
451
                                       f->cur.stride[1], pal[1],
1412
451
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
451
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
451
                                       f->cur.stride[1], pal[2],
1415
451
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
451
                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
451
            }
1425
1426
250k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
250k
                                 sm_uv_flag(&t->l, cby4);
1428
250k
            const int uv_sb_has_tr =
1429
250k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
244k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
250k
            const int uv_sb_has_bl =
1432
250k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
244k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
250k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
750k
            for (int pl = 0; pl < 2; pl++) {
1436
1.13M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
633k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
633k
                {
1439
633k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
633k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
633k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.45M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
821k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
821k
                    {
1445
821k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
644k
                            b->pal_sz[1])
1447
180k
                        {
1448
180k
                            goto skip_uv_pred;
1449
180k
                        }
1450
1451
641k
                        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
641k
                        const enum EdgeFlags edge_flags =
1456
641k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
317k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
460k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
641k
                            ((x > (init_x >> ss_hor) ||
1460
453k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
329k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
641k
                        const pixel *top_sb_edge = NULL;
1463
641k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
212k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
212k
                            const int sby = t->by >> f->sb_shift;
1466
212k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
212k
                        }
1468
641k
                        const enum IntraPredMode uv_mode =
1469
641k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
641k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
641k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
641k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
641k
                        const enum IntraPredMode m =
1474
641k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
641k
                                                              ypos, ypos > ystart,
1476
641k
                                                              ts->tiling.col_end >> ss_hor,
1477
641k
                                                              ts->tiling.row_end >> ss_ver,
1478
641k
                                                              edge_flags, dst, stride,
1479
641k
                                                              top_sb_edge, uv_mode,
1480
641k
                                                              &angle, uv_t_dim->w,
1481
641k
                                                              uv_t_dim->h,
1482
641k
                                                              f->seq_hdr->intra_edge_filter,
1483
641k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
641k
                        angle |= intra_edge_filter_flag;
1485
641k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
641k
                                                 uv_t_dim->w * 4,
1487
641k
                                                 uv_t_dim->h * 4,
1488
641k
                                                 angle | sm_uv_fl,
1489
641k
                                                 (4 * f->bw + ss_hor -
1490
641k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
641k
                                                 (4 * f->bh + ss_ver -
1492
641k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
641k
                                                 HIGHBD_CALL_SUFFIX);
1494
641k
                        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
821k
                    skip_uv_pred: {}
1505
821k
                        if (!b->skip) {
1506
295k
                            enum TxfmType txtp;
1507
295k
                            int eob;
1508
295k
                            coef *cf;
1509
295k
                            if (t->frame_thread.pass) {
1510
295k
                                const int p = t->frame_thread.pass & 1;
1511
295k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
295k
                                cf = ts->frame_thread[p].cf;
1513
295k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
295k
                                eob  = cbi >> 5;
1515
295k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                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
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
295k
                            if (eob >= 0) {
1533
137k
                                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
137k
                                dsp->itx.itxfm_add[b->uvtx]
1537
137k
                                                  [txtp](dst, stride,
1538
137k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
137k
                                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
137k
                            }
1543
526k
                        } 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
821k
                        dst += uv_t_dim->w * 4;
1548
821k
                    }
1549
633k
                    t->bx -= x << ss_hor;
1550
633k
                }
1551
500k
                t->by -= y << ss_ver;
1552
500k
            }
1553
250k
        }
1554
278k
    }
1555
265k
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
126k
{
1180
126k
    Dav1dTileState *const ts = t->ts;
1181
126k
    const Dav1dFrameContext *const f = t->f;
1182
126k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
126k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
126k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
126k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
126k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
126k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
126k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
126k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
126k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
126k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
119k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
116k
                           (bh4 > ss_ver || t->by & 1);
1194
126k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
126k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
126k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
126k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
126k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
258k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
132k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
132k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
267k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
135k
            if (b->pal_sz[0]) {
1208
408
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
408
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
408
                const uint8_t *pal_idx;
1211
408
                if (t->frame_thread.pass) {
1212
408
                    const int p = t->frame_thread.pass & 1;
1213
408
                    assert(ts->frame_thread[p].pal_idx);
1214
408
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
408
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
408
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
408
                const pixel *const pal = t->frame_thread.pass ?
1220
408
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
408
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
408
                    bytefn(t->scratch.pal)[0];
1223
408
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
408
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
408
                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
408
            }
1229
1230
135k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
135k
                                     sm_flag(&t->l, by4) |
1232
135k
                                     intra_edge_filter_flag);
1233
135k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
132k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
135k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
132k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
135k
            int y, x;
1238
135k
            const int sub_w4 = imin(w4, init_x + 16);
1239
335k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
200k
                 y += t_dim->h, t->by += t_dim->h)
1241
200k
            {
1242
200k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
200k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
200k
                                    t->bx + init_x);
1245
506k
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
305k
                     x += t_dim->w, t->bx += t_dim->w)
1247
305k
                {
1248
305k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
304k
                    int angle = b->y_angle;
1251
304k
                    const enum EdgeFlags edge_flags =
1252
304k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
215k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
304k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
163k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
304k
                    const pixel *top_sb_edge = NULL;
1257
304k
                    if (!(t->by & (f->sb_step - 1))) {
1258
76.1k
                        top_sb_edge = f->ipred_edge[0];
1259
76.1k
                        const int sby = t->by >> f->sb_shift;
1260
76.1k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
76.1k
                    }
1262
304k
                    const enum IntraPredMode m =
1263
304k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
304k
                                                          t->bx > ts->tiling.col_start,
1265
304k
                                                          t->by,
1266
304k
                                                          t->by > ts->tiling.row_start,
1267
304k
                                                          ts->tiling.col_end,
1268
304k
                                                          ts->tiling.row_end,
1269
304k
                                                          edge_flags, dst,
1270
304k
                                                          f->cur.stride[0], top_sb_edge,
1271
304k
                                                          b->y_mode, &angle,
1272
304k
                                                          t_dim->w, t_dim->h,
1273
304k
                                                          f->seq_hdr->intra_edge_filter,
1274
304k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
304k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
304k
                                             t_dim->w * 4, t_dim->h * 4,
1277
304k
                                             angle | intra_flags,
1278
304k
                                             4 * f->bw - 4 * t->bx,
1279
304k
                                             4 * f->bh - 4 * t->by
1280
304k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
304k
                    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
305k
                skip_y_pred: {}
1293
305k
                    if (!b->skip) {
1294
102k
                        coef *cf;
1295
102k
                        int eob;
1296
102k
                        enum TxfmType txtp;
1297
102k
                        if (t->frame_thread.pass) {
1298
102k
                            const int p = t->frame_thread.pass & 1;
1299
102k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
102k
                            cf = ts->frame_thread[p].cf;
1301
102k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
102k
                            eob  = cbi >> 5;
1303
102k
                            txtp = cbi & 0x1f;
1304
102k
                        } 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
102k
                        if (eob >= 0) {
1317
75.6k
                            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
75.6k
                            dsp->itx.itxfm_add[b->tx]
1321
75.6k
                                              [txtp](dst,
1322
75.6k
                                                     f->cur.stride[0],
1323
75.6k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
75.6k
                            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
75.6k
                        }
1328
203k
                    } 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
305k
                    dst += 4 * t_dim->w;
1333
305k
                }
1334
200k
                t->bx -= x;
1335
200k
            }
1336
135k
            t->by -= y;
1337
1338
135k
            if (!has_chroma) continue;
1339
1340
121k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
121k
            if (b->uv_mode == CFL_PRED) {
1343
45.7k
                assert(!init_x && !init_y);
1344
1345
45.7k
                int16_t *const ac = t->scratch.ac;
1346
45.7k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
45.7k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
45.7k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
45.7k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
45.7k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
45.7k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
45.7k
                const int furthest_r =
1354
45.7k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
45.7k
                const int furthest_b =
1356
45.7k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
45.7k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
45.7k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
45.7k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
45.7k
                                                         cbw4 * 4, cbh4 * 4);
1361
137k
                for (int pl = 0; pl < 2; pl++) {
1362
91.5k
                    if (!b->cfl_alpha[pl]) continue;
1363
85.2k
                    int angle = 0;
1364
85.2k
                    const pixel *top_sb_edge = NULL;
1365
85.2k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
22.4k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
22.4k
                        const int sby = t->by >> f->sb_shift;
1368
22.4k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
22.4k
                    }
1370
85.2k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
85.2k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
85.2k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
85.2k
                    const enum IntraPredMode m =
1374
85.2k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
85.2k
                                                          ypos, ypos > ystart,
1376
85.2k
                                                          ts->tiling.col_end >> ss_hor,
1377
85.2k
                                                          ts->tiling.row_end >> ss_ver,
1378
85.2k
                                                          0, uv_dst[pl], stride,
1379
85.2k
                                                          top_sb_edge, DC_PRED, &angle,
1380
85.2k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
85.2k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
85.2k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
85.2k
                                           uv_t_dim->w * 4,
1384
85.2k
                                           uv_t_dim->h * 4,
1385
85.2k
                                           ac, b->cfl_alpha[pl]
1386
85.2k
                                           HIGHBD_CALL_SUFFIX);
1387
85.2k
                }
1388
45.7k
                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
76.0k
            } else if (b->pal_sz[1]) {
1394
341
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
341
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
341
                const pixel (*pal)[8];
1397
341
                const uint8_t *pal_idx;
1398
341
                if (t->frame_thread.pass) {
1399
341
                    const int p = t->frame_thread.pass & 1;
1400
341
                    assert(ts->frame_thread[p].pal_idx);
1401
341
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
341
                                              ((t->bx >> 1) + (t->by & 1))];
1403
341
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
341
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
341
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
341
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
341
                                       f->cur.stride[1], pal[1],
1412
341
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
341
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
341
                                       f->cur.stride[1], pal[2],
1415
341
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
341
                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
341
            }
1425
1426
121k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
121k
                                 sm_uv_flag(&t->l, cby4);
1428
121k
            const int uv_sb_has_tr =
1429
121k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
119k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
121k
            const int uv_sb_has_bl =
1432
121k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
119k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
121k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
365k
            for (int pl = 0; pl < 2; pl++) {
1436
562k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
318k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
318k
                {
1439
318k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
318k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
318k
                                        ((t->bx + init_x) >> ss_hor));
1442
707k
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
389k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
389k
                    {
1445
389k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
303k
                            b->pal_sz[1])
1447
87.4k
                        {
1448
87.4k
                            goto skip_uv_pred;
1449
87.4k
                        }
1450
1451
301k
                        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
301k
                        const enum EdgeFlags edge_flags =
1456
301k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
149k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
203k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
301k
                            ((x > (init_x >> ss_hor) ||
1460
231k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
167k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
301k
                        const pixel *top_sb_edge = NULL;
1463
301k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
95.4k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
95.4k
                            const int sby = t->by >> f->sb_shift;
1466
95.4k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
95.4k
                        }
1468
301k
                        const enum IntraPredMode uv_mode =
1469
301k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
301k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
301k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
301k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
301k
                        const enum IntraPredMode m =
1474
301k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
301k
                                                              ypos, ypos > ystart,
1476
301k
                                                              ts->tiling.col_end >> ss_hor,
1477
301k
                                                              ts->tiling.row_end >> ss_ver,
1478
301k
                                                              edge_flags, dst, stride,
1479
301k
                                                              top_sb_edge, uv_mode,
1480
301k
                                                              &angle, uv_t_dim->w,
1481
301k
                                                              uv_t_dim->h,
1482
301k
                                                              f->seq_hdr->intra_edge_filter,
1483
301k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
301k
                        angle |= intra_edge_filter_flag;
1485
301k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
301k
                                                 uv_t_dim->w * 4,
1487
301k
                                                 uv_t_dim->h * 4,
1488
301k
                                                 angle | sm_uv_fl,
1489
301k
                                                 (4 * f->bw + ss_hor -
1490
301k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
301k
                                                 (4 * f->bh + ss_ver -
1492
301k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
301k
                                                 HIGHBD_CALL_SUFFIX);
1494
301k
                        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
389k
                    skip_uv_pred: {}
1505
389k
                        if (!b->skip) {
1506
163k
                            enum TxfmType txtp;
1507
163k
                            int eob;
1508
163k
                            coef *cf;
1509
163k
                            if (t->frame_thread.pass) {
1510
163k
                                const int p = t->frame_thread.pass & 1;
1511
163k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
163k
                                cf = ts->frame_thread[p].cf;
1513
163k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
163k
                                eob  = cbi >> 5;
1515
163k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                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
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
163k
                            if (eob >= 0) {
1533
87.0k
                                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
87.0k
                                dsp->itx.itxfm_add[b->uvtx]
1537
87.0k
                                                  [txtp](dst, stride,
1538
87.0k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
87.0k
                                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
87.0k
                            }
1543
225k
                        } 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
389k
                        dst += uv_t_dim->w * 4;
1548
389k
                    }
1549
318k
                    t->bx -= x << ss_hor;
1550
318k
                }
1551
243k
                t->by -= y << ss_ver;
1552
243k
            }
1553
121k
        }
1554
132k
    }
1555
126k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
139k
{
1180
139k
    Dav1dTileState *const ts = t->ts;
1181
139k
    const Dav1dFrameContext *const f = t->f;
1182
139k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
139k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
139k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
139k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
139k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
139k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
139k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
139k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
139k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
139k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
124k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
121k
                           (bh4 > ss_ver || t->by & 1);
1194
139k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
139k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
139k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
139k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
139k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
285k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
145k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
145k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
294k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
148k
            if (b->pal_sz[0]) {
1208
349
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
349
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
349
                const uint8_t *pal_idx;
1211
349
                if (t->frame_thread.pass) {
1212
349
                    const int p = t->frame_thread.pass & 1;
1213
349
                    assert(ts->frame_thread[p].pal_idx);
1214
349
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
349
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
349
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
349
                const pixel *const pal = t->frame_thread.pass ?
1220
349
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
349
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
349
                    bytefn(t->scratch.pal)[0];
1223
349
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
349
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
349
                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
349
            }
1229
1230
148k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
148k
                                     sm_flag(&t->l, by4) |
1232
148k
                                     intra_edge_filter_flag);
1233
148k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
145k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
148k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
145k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
148k
            int y, x;
1238
148k
            const int sub_w4 = imin(w4, init_x + 16);
1239
343k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
194k
                 y += t_dim->h, t->by += t_dim->h)
1241
194k
            {
1242
194k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
194k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
194k
                                    t->bx + init_x);
1245
495k
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
301k
                     x += t_dim->w, t->bx += t_dim->w)
1247
301k
                {
1248
301k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
300k
                    int angle = b->y_angle;
1251
300k
                    const enum EdgeFlags edge_flags =
1252
300k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
229k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
300k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
167k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
300k
                    const pixel *top_sb_edge = NULL;
1257
300k
                    if (!(t->by & (f->sb_step - 1))) {
1258
94.9k
                        top_sb_edge = f->ipred_edge[0];
1259
94.9k
                        const int sby = t->by >> f->sb_shift;
1260
94.9k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
94.9k
                    }
1262
300k
                    const enum IntraPredMode m =
1263
300k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
300k
                                                          t->bx > ts->tiling.col_start,
1265
300k
                                                          t->by,
1266
300k
                                                          t->by > ts->tiling.row_start,
1267
300k
                                                          ts->tiling.col_end,
1268
300k
                                                          ts->tiling.row_end,
1269
300k
                                                          edge_flags, dst,
1270
300k
                                                          f->cur.stride[0], top_sb_edge,
1271
300k
                                                          b->y_mode, &angle,
1272
300k
                                                          t_dim->w, t_dim->h,
1273
300k
                                                          f->seq_hdr->intra_edge_filter,
1274
300k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
300k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
300k
                                             t_dim->w * 4, t_dim->h * 4,
1277
300k
                                             angle | intra_flags,
1278
300k
                                             4 * f->bw - 4 * t->bx,
1279
300k
                                             4 * f->bh - 4 * t->by
1280
300k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
300k
                    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
301k
                skip_y_pred: {}
1293
301k
                    if (!b->skip) {
1294
96.4k
                        coef *cf;
1295
96.4k
                        int eob;
1296
96.4k
                        enum TxfmType txtp;
1297
96.4k
                        if (t->frame_thread.pass) {
1298
96.4k
                            const int p = t->frame_thread.pass & 1;
1299
96.4k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
96.4k
                            cf = ts->frame_thread[p].cf;
1301
96.4k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
96.4k
                            eob  = cbi >> 5;
1303
96.4k
                            txtp = cbi & 0x1f;
1304
96.4k
                        } 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
96.4k
                        if (eob >= 0) {
1317
63.1k
                            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
63.1k
                            dsp->itx.itxfm_add[b->tx]
1321
63.1k
                                              [txtp](dst,
1322
63.1k
                                                     f->cur.stride[0],
1323
63.1k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
63.1k
                            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
63.1k
                        }
1328
204k
                    } 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
301k
                    dst += 4 * t_dim->w;
1333
301k
                }
1334
194k
                t->bx -= x;
1335
194k
            }
1336
148k
            t->by -= y;
1337
1338
148k
            if (!has_chroma) continue;
1339
1340
128k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
128k
            if (b->uv_mode == CFL_PRED) {
1343
49.4k
                assert(!init_x && !init_y);
1344
1345
49.4k
                int16_t *const ac = t->scratch.ac;
1346
49.4k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
49.4k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
49.4k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
49.4k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
49.4k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
49.4k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
49.4k
                const int furthest_r =
1354
49.4k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
49.4k
                const int furthest_b =
1356
49.4k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
49.4k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
49.4k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
49.4k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
49.4k
                                                         cbw4 * 4, cbh4 * 4);
1361
148k
                for (int pl = 0; pl < 2; pl++) {
1362
98.8k
                    if (!b->cfl_alpha[pl]) continue;
1363
92.1k
                    int angle = 0;
1364
92.1k
                    const pixel *top_sb_edge = NULL;
1365
92.1k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
25.6k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
25.6k
                        const int sby = t->by >> f->sb_shift;
1368
25.6k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
25.6k
                    }
1370
92.1k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
92.1k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
92.1k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
92.1k
                    const enum IntraPredMode m =
1374
92.1k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
92.1k
                                                          ypos, ypos > ystart,
1376
92.1k
                                                          ts->tiling.col_end >> ss_hor,
1377
92.1k
                                                          ts->tiling.row_end >> ss_ver,
1378
92.1k
                                                          0, uv_dst[pl], stride,
1379
92.1k
                                                          top_sb_edge, DC_PRED, &angle,
1380
92.1k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
92.1k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
92.1k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
92.1k
                                           uv_t_dim->w * 4,
1384
92.1k
                                           uv_t_dim->h * 4,
1385
92.1k
                                           ac, b->cfl_alpha[pl]
1386
92.1k
                                           HIGHBD_CALL_SUFFIX);
1387
92.1k
                }
1388
49.4k
                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
78.8k
            } else if (b->pal_sz[1]) {
1394
110
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
110
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
110
                const pixel (*pal)[8];
1397
110
                const uint8_t *pal_idx;
1398
110
                if (t->frame_thread.pass) {
1399
110
                    const int p = t->frame_thread.pass & 1;
1400
110
                    assert(ts->frame_thread[p].pal_idx);
1401
110
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
110
                                              ((t->bx >> 1) + (t->by & 1))];
1403
110
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
110
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
110
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
110
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
110
                                       f->cur.stride[1], pal[1],
1412
110
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
110
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
110
                                       f->cur.stride[1], pal[2],
1415
110
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
110
                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
110
            }
1425
1426
128k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
128k
                                 sm_uv_flag(&t->l, cby4);
1428
128k
            const int uv_sb_has_tr =
1429
128k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
125k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
128k
            const int uv_sb_has_bl =
1432
128k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
125k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
128k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
384k
            for (int pl = 0; pl < 2; pl++) {
1436
571k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
314k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
314k
                {
1439
314k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
314k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
314k
                                        ((t->bx + init_x) >> ss_hor));
1442
747k
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
432k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
432k
                    {
1445
432k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
340k
                            b->pal_sz[1])
1447
92.7k
                        {
1448
92.7k
                            goto skip_uv_pred;
1449
92.7k
                        }
1450
1451
339k
                        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
339k
                        const enum EdgeFlags edge_flags =
1456
339k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
168k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
256k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
339k
                            ((x > (init_x >> ss_hor) ||
1460
222k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
177k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
339k
                        const pixel *top_sb_edge = NULL;
1463
339k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
116k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
116k
                            const int sby = t->by >> f->sb_shift;
1466
116k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
116k
                        }
1468
339k
                        const enum IntraPredMode uv_mode =
1469
339k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
339k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
339k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
339k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
339k
                        const enum IntraPredMode m =
1474
339k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
339k
                                                              ypos, ypos > ystart,
1476
339k
                                                              ts->tiling.col_end >> ss_hor,
1477
339k
                                                              ts->tiling.row_end >> ss_ver,
1478
339k
                                                              edge_flags, dst, stride,
1479
339k
                                                              top_sb_edge, uv_mode,
1480
339k
                                                              &angle, uv_t_dim->w,
1481
339k
                                                              uv_t_dim->h,
1482
339k
                                                              f->seq_hdr->intra_edge_filter,
1483
339k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
339k
                        angle |= intra_edge_filter_flag;
1485
339k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
339k
                                                 uv_t_dim->w * 4,
1487
339k
                                                 uv_t_dim->h * 4,
1488
339k
                                                 angle | sm_uv_fl,
1489
339k
                                                 (4 * f->bw + ss_hor -
1490
339k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
339k
                                                 (4 * f->bh + ss_ver -
1492
339k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
339k
                                                 HIGHBD_CALL_SUFFIX);
1494
339k
                        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
432k
                    skip_uv_pred: {}
1505
432k
                        if (!b->skip) {
1506
131k
                            enum TxfmType txtp;
1507
131k
                            int eob;
1508
131k
                            coef *cf;
1509
131k
                            if (t->frame_thread.pass) {
1510
131k
                                const int p = t->frame_thread.pass & 1;
1511
131k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
131k
                                cf = ts->frame_thread[p].cf;
1513
131k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
131k
                                eob  = cbi >> 5;
1515
131k
                                txtp = cbi & 0x1f;
1516
131k
                            } 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
131k
                            if (eob >= 0) {
1533
50.1k
                                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
50.1k
                                dsp->itx.itxfm_add[b->uvtx]
1537
50.1k
                                                  [txtp](dst, stride,
1538
50.1k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
50.1k
                                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
50.1k
                            }
1543
300k
                        } 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
432k
                        dst += uv_t_dim->w * 4;
1548
432k
                    }
1549
314k
                    t->bx -= x << ss_hor;
1550
314k
                }
1551
256k
                t->by -= y << ss_ver;
1552
256k
            }
1553
128k
        }
1554
145k
    }
1555
139k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
73.3k
{
1560
73.3k
    Dav1dTileState *const ts = t->ts;
1561
73.3k
    const Dav1dFrameContext *const f = t->f;
1562
73.3k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
73.3k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
73.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
73.3k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
73.3k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
73.3k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
73.3k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
73.3k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
73.3k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
70.6k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
68.9k
                           (bh4 > ss_ver || t->by & 1);
1573
73.3k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
73.3k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
73.3k
    int res;
1576
1577
    // prediction
1578
73.3k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
73.3k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
73.3k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
73.3k
    const ptrdiff_t uvdstoff =
1582
73.3k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
73.3k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
48.8k
        assert(!f->frame_hdr->super_res.enabled);
1586
48.8k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
48.8k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
48.8k
        if (res) return res;
1589
142k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
94.6k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
94.6k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
94.6k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
94.6k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
94.6k
            if (res) return res;
1595
94.6k
        }
1596
48.8k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
20.9k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
20.9k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
20.9k
        if (imin(bw4, bh4) > 1 &&
1601
12.5k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
11.1k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.68k
        {
1604
1.68k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.68k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.68k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.68k
            if (res) return res;
1608
19.2k
        } else {
1609
19.2k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
19.2k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
19.2k
            if (res) return res;
1612
19.2k
            if (b->motion_mode == MM_OBMC) {
1613
3.68k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
3.68k
                if (res) return res;
1615
3.68k
            }
1616
19.2k
        }
1617
20.9k
        if (b->interintra_type) {
1618
1.08k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
1.08k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
896
                                   SMOOTH_PRED : b->interintra_mode;
1621
1.08k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
1.08k
            int angle = 0;
1623
1.08k
            const pixel *top_sb_edge = NULL;
1624
1.08k
            if (!(t->by & (f->sb_step - 1))) {
1625
203
                top_sb_edge = f->ipred_edge[0];
1626
203
                const int sby = t->by >> f->sb_shift;
1627
203
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
203
            }
1629
1.08k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
1.08k
                                                  t->by, t->by > ts->tiling.row_start,
1631
1.08k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
1.08k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
1.08k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
1.08k
                                                  HIGHBD_CALL_SUFFIX);
1635
1.08k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
1.08k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
1.08k
                                     HIGHBD_CALL_SUFFIX);
1638
1.08k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
1.08k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
1.08k
        }
1641
1642
20.9k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
17.5k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
17.5k
        refmvs_block *const *r;
1647
17.5k
        if (is_sub8x8) {
1648
960
            assert(ss_hor == 1);
1649
960
            r = &t->rt.r[(t->by & 31) + 5];
1650
960
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
960
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
960
            if (bw4 == 1 && bh4 == ss_ver)
1653
390
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
960
        }
1655
1656
        // chroma prediction
1657
17.5k
        if (is_sub8x8) {
1658
948
            assert(ss_hor == 1);
1659
948
            ptrdiff_t h_off = 0, v_off = 0;
1660
948
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.15k
                for (int pl = 0; pl < 2; pl++) {
1662
772
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
772
                             NULL, f->cur.stride[1],
1664
772
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
772
                             r[-1][t->bx - 1].mv.mv[0],
1666
772
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
772
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
772
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
772
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
772
                    if (res) return res;
1671
772
                }
1672
386
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
386
                h_off = 2;
1674
386
            }
1675
948
            if (bw4 == 1) {
1676
655
                const enum Filter2d left_filter_2d =
1677
655
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
1.96k
                for (int pl = 0; pl < 2; pl++) {
1679
1.31k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
1.31k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
1.31k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
1.31k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
1.31k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
1.31k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
1.31k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
1.31k
                    if (res) return res;
1687
1.31k
                }
1688
655
                h_off = 2;
1689
655
            }
1690
948
            if (bh4 == ss_ver) {
1691
679
                const enum Filter2d top_filter_2d =
1692
679
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
2.03k
                for (int pl = 0; pl < 2; pl++) {
1694
1.35k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
1.35k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
1.35k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
1.35k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
1.35k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
1.35k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
1.35k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
1.35k
                    if (res) return res;
1702
1.35k
                }
1703
679
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
679
            }
1705
2.84k
            for (int pl = 0; pl < 2; pl++) {
1706
1.89k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
1.89k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
1.89k
                         refp, b->ref[0], filter_2d);
1709
1.89k
                if (res) return res;
1710
1.89k
            }
1711
16.6k
        } else {
1712
16.6k
            if (imin(cbw4, cbh4) > 1 &&
1713
9.83k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
8.58k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.56k
            {
1716
4.69k
                for (int pl = 0; pl < 2; pl++) {
1717
3.12k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
3.12k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
3.12k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
3.12k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
3.12k
                    if (res) return res;
1722
3.12k
                }
1723
15.0k
            } else {
1724
45.1k
                for (int pl = 0; pl < 2; pl++) {
1725
30.1k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
30.1k
                             NULL, f->cur.stride[1],
1727
30.1k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
30.1k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
30.1k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
30.1k
                    if (res) return res;
1731
30.1k
                    if (b->motion_mode == MM_OBMC) {
1732
6.86k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
6.86k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
6.86k
                        if (res) return res;
1735
6.86k
                    }
1736
30.1k
                }
1737
15.0k
            }
1738
16.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
1.01k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
3.03k
                for (int pl = 0; pl < 2; pl++) {
1745
2.02k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
2.02k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
2.02k
                    enum IntraPredMode m =
1748
2.02k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.67k
                        SMOOTH_PRED : b->interintra_mode;
1750
2.02k
                    int angle = 0;
1751
2.02k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
2.02k
                    const pixel *top_sb_edge = NULL;
1753
2.02k
                    if (!(t->by & (f->sb_step - 1))) {
1754
346
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
346
                        const int sby = t->by >> f->sb_shift;
1756
346
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
346
                    }
1758
2.02k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
2.02k
                                                          (t->bx >> ss_hor) >
1760
2.02k
                                                              (ts->tiling.col_start >> ss_hor),
1761
2.02k
                                                          t->by >> ss_ver,
1762
2.02k
                                                          (t->by >> ss_ver) >
1763
2.02k
                                                              (ts->tiling.row_start >> ss_ver),
1764
2.02k
                                                          ts->tiling.col_end >> ss_hor,
1765
2.02k
                                                          ts->tiling.row_end >> ss_ver,
1766
2.02k
                                                          0, uvdst, f->cur.stride[1],
1767
2.02k
                                                          top_sb_edge, m,
1768
2.02k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
2.02k
                                                          HIGHBD_CALL_SUFFIX);
1770
2.02k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
2.02k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
2.02k
                                             HIGHBD_CALL_SUFFIX);
1773
2.02k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
2.02k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
2.02k
                }
1776
1.01k
            }
1777
16.6k
        }
1778
1779
20.9k
    skip_inter_chroma_pred: {}
1780
20.9k
        t->tl_4x4_filter = filter_2d;
1781
20.9k
    } else {
1782
3.45k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
3.45k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
3.45k
        int jnt_weight;
1786
3.45k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
3.45k
        const uint8_t *mask;
1788
1789
10.3k
        for (int i = 0; i < 2; i++) {
1790
6.91k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
6.91k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
268
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
268
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
268
                if (res) return res;
1796
6.64k
            } else {
1797
6.64k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
6.64k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
6.64k
                if (res) return res;
1800
6.64k
            }
1801
6.91k
        }
1802
3.45k
        switch (b->comp_type) {
1803
2.48k
        case COMP_INTER_AVG:
1804
2.48k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
2.48k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
2.48k
            break;
1807
305
        case COMP_INTER_WEIGHTED_AVG:
1808
305
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
305
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
305
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
305
            break;
1812
457
        case COMP_INTER_SEG:
1813
457
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
457
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
457
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
457
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
457
            mask = seg_mask;
1818
457
            break;
1819
212
        case COMP_INTER_WEDGE:
1820
212
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
212
            dsp->mc.mask(dst, f->cur.stride[0],
1822
212
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
212
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
212
            if (has_chroma)
1825
190
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
212
            break;
1827
3.45k
        }
1828
1829
        // chroma
1830
9.16k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
18.3k
            for (int i = 0; i < 2; i++) {
1832
12.2k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
12.2k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
1.59k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
380
                {
1836
380
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
380
                                      b_dim, 1 + pl,
1838
380
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
380
                    if (res) return res;
1840
11.8k
                } else {
1841
11.8k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
11.8k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
11.8k
                    if (res) return res;
1844
11.8k
                }
1845
12.2k
            }
1846
6.10k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
6.10k
            switch (b->comp_type) {
1848
4.41k
            case COMP_INTER_AVG:
1849
4.41k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
4.41k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
4.41k
                            HIGHBD_CALL_SUFFIX);
1852
4.41k
                break;
1853
508
            case COMP_INTER_WEIGHTED_AVG:
1854
508
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
508
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
508
                              HIGHBD_CALL_SUFFIX);
1857
508
                break;
1858
380
            case COMP_INTER_WEDGE:
1859
1.18k
            case COMP_INTER_SEG:
1860
1.18k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
1.18k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
1.18k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
1.18k
                             HIGHBD_CALL_SUFFIX);
1864
1.18k
                break;
1865
6.10k
            }
1866
6.10k
        }
1867
3.45k
    }
1868
1869
73.3k
    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
73.3k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
73.3k
    if (b->skip) {
1882
        // reset coef contexts
1883
50.0k
        BlockContext *const a = t->a;
1884
50.0k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
50.0k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
50.0k
        if (has_chroma) {
1887
46.4k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
46.4k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
46.4k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
46.4k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
46.4k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
46.4k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
46.4k
        }
1894
50.0k
        return 0;
1895
50.0k
    }
1896
1897
23.2k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
23.2k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
23.2k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
46.8k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
47.5k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
23.9k
            int y_off = !!init_y, y;
1905
23.9k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
50.5k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
26.6k
                 y += ytx->h, y_off++)
1908
26.6k
            {
1909
26.6k
                int x, x_off = !!init_x;
1910
58.0k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
31.4k
                     x += ytx->w, x_off++)
1912
31.4k
                {
1913
31.4k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
31.4k
                                   x_off, y_off, &dst[x * 4]);
1915
31.4k
                    t->bx += ytx->w;
1916
31.4k
                }
1917
26.6k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
26.6k
                t->bx -= x;
1919
26.6k
                t->by += ytx->h;
1920
26.6k
            }
1921
23.9k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
23.9k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
65.7k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
43.8k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
43.8k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
43.8k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
94.7k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
50.9k
                {
1931
50.9k
                    int x;
1932
50.9k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
110k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
59.2k
                    {
1935
59.2k
                        coef *cf;
1936
59.2k
                        int eob;
1937
59.2k
                        enum TxfmType txtp;
1938
59.2k
                        if (t->frame_thread.pass) {
1939
59.2k
                            const int p = t->frame_thread.pass & 1;
1940
59.2k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
59.2k
                            cf = ts->frame_thread[p].cf;
1942
59.2k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
59.2k
                            eob  = cbi >> 5;
1944
59.2k
                            txtp = cbi & 0x1f;
1945
59.2k
                        } else {
1946
0
                            uint8_t cf_ctx;
1947
0
                            cf = bitfn(t->cf);
1948
0
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
0
                                                        bx4 + (x << ss_hor)];
1950
0
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
0
                                               &t->l.ccoef[pl][cby4 + y],
1952
0
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
0
                                               cf, &txtp, &cf_ctx);
1954
0
                            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
0
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
0
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
0
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
0
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
0
                        }
1963
59.2k
                        if (eob >= 0) {
1964
20.3k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
20.3k
                            dsp->itx.itxfm_add[b->uvtx]
1967
20.3k
                                              [txtp](&uvdst[4 * x],
1968
20.3k
                                                     f->cur.stride[1],
1969
20.3k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
20.3k
                            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
20.3k
                        }
1974
59.2k
                        t->bx += uvtx->w << ss_hor;
1975
59.2k
                    }
1976
50.9k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
50.9k
                    t->bx -= x << ss_hor;
1978
50.9k
                    t->by += uvtx->h << ss_ver;
1979
50.9k
                }
1980
43.8k
                t->by -= y << ss_ver;
1981
43.8k
            }
1982
23.9k
        }
1983
23.6k
    }
1984
23.2k
    return 0;
1985
73.3k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
46.0k
{
1560
46.0k
    Dav1dTileState *const ts = t->ts;
1561
46.0k
    const Dav1dFrameContext *const f = t->f;
1562
46.0k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
46.0k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
46.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
46.0k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
46.0k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
46.0k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
46.0k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
46.0k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
46.0k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
44.5k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
43.8k
                           (bh4 > ss_ver || t->by & 1);
1573
46.0k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
46.0k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
46.0k
    int res;
1576
1577
    // prediction
1578
46.0k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
46.0k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
46.0k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
46.0k
    const ptrdiff_t uvdstoff =
1582
46.0k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
46.0k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
32.4k
        assert(!f->frame_hdr->super_res.enabled);
1586
32.4k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
32.4k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
32.4k
        if (res) return res;
1589
95.5k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
63.7k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
63.7k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
63.7k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
63.7k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
63.7k
            if (res) return res;
1595
63.7k
        }
1596
32.4k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
11.9k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
11.9k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
11.9k
        if (imin(bw4, bh4) > 1 &&
1601
7.04k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
6.17k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.09k
        {
1604
1.09k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.09k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.09k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.09k
            if (res) return res;
1608
10.8k
        } else {
1609
10.8k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
10.8k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
10.8k
            if (res) return res;
1612
10.8k
            if (b->motion_mode == MM_OBMC) {
1613
2.04k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
2.04k
                if (res) return res;
1615
2.04k
            }
1616
10.8k
        }
1617
11.9k
        if (b->interintra_type) {
1618
683
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
683
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
579
                                   SMOOTH_PRED : b->interintra_mode;
1621
683
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
683
            int angle = 0;
1623
683
            const pixel *top_sb_edge = NULL;
1624
683
            if (!(t->by & (f->sb_step - 1))) {
1625
127
                top_sb_edge = f->ipred_edge[0];
1626
127
                const int sby = t->by >> f->sb_shift;
1627
127
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
127
            }
1629
683
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
683
                                                  t->by, t->by > ts->tiling.row_start,
1631
683
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
683
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
683
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
683
                                                  HIGHBD_CALL_SUFFIX);
1635
683
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
683
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
683
                                     HIGHBD_CALL_SUFFIX);
1638
683
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
683
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
683
        }
1641
1642
11.9k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
10.1k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
10.1k
        refmvs_block *const *r;
1647
10.1k
        if (is_sub8x8) {
1648
497
            assert(ss_hor == 1);
1649
497
            r = &t->rt.r[(t->by & 31) + 5];
1650
497
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
497
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
497
            if (bw4 == 1 && bh4 == ss_ver)
1653
206
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
497
        }
1655
1656
        // chroma prediction
1657
10.1k
        if (is_sub8x8) {
1658
490
            assert(ss_hor == 1);
1659
490
            ptrdiff_t h_off = 0, v_off = 0;
1660
490
            if (bw4 == 1 && bh4 == ss_ver) {
1661
609
                for (int pl = 0; pl < 2; pl++) {
1662
406
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
406
                             NULL, f->cur.stride[1],
1664
406
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
406
                             r[-1][t->bx - 1].mv.mv[0],
1666
406
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
406
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
406
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
406
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
406
                    if (res) return res;
1671
406
                }
1672
203
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
203
                h_off = 2;
1674
203
            }
1675
490
            if (bw4 == 1) {
1676
338
                const enum Filter2d left_filter_2d =
1677
338
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
1.01k
                for (int pl = 0; pl < 2; pl++) {
1679
676
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
676
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
676
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
676
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
676
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
676
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
676
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
676
                    if (res) return res;
1687
676
                }
1688
338
                h_off = 2;
1689
338
            }
1690
490
            if (bh4 == ss_ver) {
1691
355
                const enum Filter2d top_filter_2d =
1692
355
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
1.06k
                for (int pl = 0; pl < 2; pl++) {
1694
710
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
710
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
710
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
710
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
710
                             r[-1][t->bx].ref.ref[0] - 1,
1699
710
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
710
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
710
                    if (res) return res;
1702
710
                }
1703
355
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
355
            }
1705
1.47k
            for (int pl = 0; pl < 2; pl++) {
1706
980
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
980
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
980
                         refp, b->ref[0], filter_2d);
1709
980
                if (res) return res;
1710
980
            }
1711
9.61k
        } else {
1712
9.61k
            if (imin(cbw4, cbh4) > 1 &&
1713
5.59k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
4.80k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.00k
            {
1716
3.02k
                for (int pl = 0; pl < 2; pl++) {
1717
2.01k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
2.01k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
2.01k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
2.01k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
2.01k
                    if (res) return res;
1722
2.01k
                }
1723
8.60k
            } else {
1724
25.8k
                for (int pl = 0; pl < 2; pl++) {
1725
17.2k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
17.2k
                             NULL, f->cur.stride[1],
1727
17.2k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
17.2k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
17.2k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
17.2k
                    if (res) return res;
1731
17.2k
                    if (b->motion_mode == MM_OBMC) {
1732
3.80k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
3.80k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
3.80k
                        if (res) return res;
1735
3.80k
                    }
1736
17.2k
                }
1737
8.60k
            }
1738
9.61k
            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
636
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
1.90k
                for (int pl = 0; pl < 2; pl++) {
1745
1.27k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.27k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.27k
                    enum IntraPredMode m =
1748
1.27k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.08k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.27k
                    int angle = 0;
1751
1.27k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.27k
                    const pixel *top_sb_edge = NULL;
1753
1.27k
                    if (!(t->by & (f->sb_step - 1))) {
1754
218
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
218
                        const int sby = t->by >> f->sb_shift;
1756
218
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
218
                    }
1758
1.27k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.27k
                                                          (t->bx >> ss_hor) >
1760
1.27k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.27k
                                                          t->by >> ss_ver,
1762
1.27k
                                                          (t->by >> ss_ver) >
1763
1.27k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.27k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.27k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.27k
                                                          0, uvdst, f->cur.stride[1],
1767
1.27k
                                                          top_sb_edge, m,
1768
1.27k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.27k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.27k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.27k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.27k
                                             HIGHBD_CALL_SUFFIX);
1773
1.27k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.27k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.27k
                }
1776
636
            }
1777
9.61k
        }
1778
1779
11.9k
    skip_inter_chroma_pred: {}
1780
11.9k
        t->tl_4x4_filter = filter_2d;
1781
11.9k
    } else {
1782
1.65k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
1.65k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
1.65k
        int jnt_weight;
1786
1.65k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
1.65k
        const uint8_t *mask;
1788
1789
4.96k
        for (int i = 0; i < 2; i++) {
1790
3.31k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
3.31k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
125
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
125
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
125
                if (res) return res;
1796
3.18k
            } else {
1797
3.18k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
3.18k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
3.18k
                if (res) return res;
1800
3.18k
            }
1801
3.31k
        }
1802
1.65k
        switch (b->comp_type) {
1803
1.19k
        case COMP_INTER_AVG:
1804
1.19k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
1.19k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
1.19k
            break;
1807
144
        case COMP_INTER_WEIGHTED_AVG:
1808
144
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
144
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
144
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
144
            break;
1812
229
        case COMP_INTER_SEG:
1813
229
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
229
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
229
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
229
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
229
            mask = seg_mask;
1818
229
            break;
1819
92
        case COMP_INTER_WEDGE:
1820
92
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
92
            dsp->mc.mask(dst, f->cur.stride[0],
1822
92
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
92
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
92
            if (has_chroma)
1825
85
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
92
            break;
1827
1.65k
        }
1828
1829
        // chroma
1830
4.20k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
8.41k
            for (int i = 0; i < 2; i++) {
1832
5.61k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
5.61k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
692
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
158
                {
1836
158
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
158
                                      b_dim, 1 + pl,
1838
158
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
158
                    if (res) return res;
1840
5.45k
                } else {
1841
5.45k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
5.45k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
5.45k
                    if (res) return res;
1844
5.45k
                }
1845
5.61k
            }
1846
2.80k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
2.80k
            switch (b->comp_type) {
1848
1.99k
            case COMP_INTER_AVG:
1849
1.99k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
1.99k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
1.99k
                            HIGHBD_CALL_SUFFIX);
1852
1.99k
                break;
1853
244
            case COMP_INTER_WEIGHTED_AVG:
1854
244
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
244
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
244
                              HIGHBD_CALL_SUFFIX);
1857
244
                break;
1858
170
            case COMP_INTER_WEDGE:
1859
572
            case COMP_INTER_SEG:
1860
572
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
572
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
572
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
572
                             HIGHBD_CALL_SUFFIX);
1864
572
                break;
1865
2.80k
            }
1866
2.80k
        }
1867
1.65k
    }
1868
1869
46.0k
    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
46.0k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
46.0k
    if (b->skip) {
1882
        // reset coef contexts
1883
34.3k
        BlockContext *const a = t->a;
1884
34.3k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
34.3k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
34.3k
        if (has_chroma) {
1887
32.6k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
32.6k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
32.6k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
32.6k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
32.6k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
32.6k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
32.6k
        }
1894
34.3k
        return 0;
1895
34.3k
    }
1896
1897
11.6k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
11.6k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
11.6k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
23.4k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
23.7k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
11.9k
            int y_off = !!init_y, y;
1905
11.9k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
25.4k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
13.5k
                 y += ytx->h, y_off++)
1908
13.5k
            {
1909
13.5k
                int x, x_off = !!init_x;
1910
29.7k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
16.2k
                     x += ytx->w, x_off++)
1912
16.2k
                {
1913
16.2k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
16.2k
                                   x_off, y_off, &dst[x * 4]);
1915
16.2k
                    t->bx += ytx->w;
1916
16.2k
                }
1917
13.5k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
13.5k
                t->bx -= x;
1919
13.5k
                t->by += ytx->h;
1920
13.5k
            }
1921
11.9k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
11.9k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
32.8k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
21.8k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
21.8k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
21.8k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
47.8k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
25.9k
                {
1931
25.9k
                    int x;
1932
25.9k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
56.5k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
30.6k
                    {
1935
30.6k
                        coef *cf;
1936
30.6k
                        int eob;
1937
30.6k
                        enum TxfmType txtp;
1938
30.6k
                        if (t->frame_thread.pass) {
1939
30.6k
                            const int p = t->frame_thread.pass & 1;
1940
30.6k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
30.6k
                            cf = ts->frame_thread[p].cf;
1942
30.6k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
30.6k
                            eob  = cbi >> 5;
1944
30.6k
                            txtp = cbi & 0x1f;
1945
30.6k
                        } else {
1946
0
                            uint8_t cf_ctx;
1947
0
                            cf = bitfn(t->cf);
1948
0
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
0
                                                        bx4 + (x << ss_hor)];
1950
0
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
0
                                               &t->l.ccoef[pl][cby4 + y],
1952
0
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
0
                                               cf, &txtp, &cf_ctx);
1954
0
                            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
0
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
0
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
0
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
0
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
0
                        }
1963
30.6k
                        if (eob >= 0) {
1964
11.3k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
11.3k
                            dsp->itx.itxfm_add[b->uvtx]
1967
11.3k
                                              [txtp](&uvdst[4 * x],
1968
11.3k
                                                     f->cur.stride[1],
1969
11.3k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
11.3k
                            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
11.3k
                        }
1974
30.6k
                        t->bx += uvtx->w << ss_hor;
1975
30.6k
                    }
1976
25.9k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
25.9k
                    t->bx -= x << ss_hor;
1978
25.9k
                    t->by += uvtx->h << ss_ver;
1979
25.9k
                }
1980
21.8k
                t->by -= y << ss_ver;
1981
21.8k
            }
1982
11.9k
        }
1983
11.8k
    }
1984
11.6k
    return 0;
1985
46.0k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
27.2k
{
1560
27.2k
    Dav1dTileState *const ts = t->ts;
1561
27.2k
    const Dav1dFrameContext *const f = t->f;
1562
27.2k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
27.2k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
27.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
27.2k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
27.2k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
27.2k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
27.2k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
27.2k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
27.2k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
26.0k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
25.1k
                           (bh4 > ss_ver || t->by & 1);
1573
27.2k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
27.2k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
27.2k
    int res;
1576
1577
    // prediction
1578
27.2k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
27.2k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
27.2k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
27.2k
    const ptrdiff_t uvdstoff =
1582
27.2k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
27.2k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
16.4k
        assert(!f->frame_hdr->super_res.enabled);
1586
16.4k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
16.4k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
16.4k
        if (res) return res;
1589
46.4k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
30.9k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
30.9k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
30.9k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
30.9k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
30.9k
            if (res) return res;
1595
30.9k
        }
1596
16.4k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
9.03k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
9.03k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
9.03k
        if (imin(bw4, bh4) > 1 &&
1601
5.46k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
4.96k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
599
        {
1604
599
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
599
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
599
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
599
            if (res) return res;
1608
8.43k
        } else {
1609
8.43k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
8.43k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
8.43k
            if (res) return res;
1612
8.43k
            if (b->motion_mode == MM_OBMC) {
1613
1.63k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
1.63k
                if (res) return res;
1615
1.63k
            }
1616
8.43k
        }
1617
9.03k
        if (b->interintra_type) {
1618
400
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
400
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
317
                                   SMOOTH_PRED : b->interintra_mode;
1621
400
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
400
            int angle = 0;
1623
400
            const pixel *top_sb_edge = NULL;
1624
400
            if (!(t->by & (f->sb_step - 1))) {
1625
76
                top_sb_edge = f->ipred_edge[0];
1626
76
                const int sby = t->by >> f->sb_shift;
1627
76
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
76
            }
1629
400
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
400
                                                  t->by, t->by > ts->tiling.row_start,
1631
400
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
400
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
400
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
400
                                                  HIGHBD_CALL_SUFFIX);
1635
400
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
400
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
400
                                     HIGHBD_CALL_SUFFIX);
1638
400
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
400
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
400
        }
1641
1642
9.03k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
7.46k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
7.46k
        refmvs_block *const *r;
1647
7.46k
        if (is_sub8x8) {
1648
463
            assert(ss_hor == 1);
1649
463
            r = &t->rt.r[(t->by & 31) + 5];
1650
463
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
463
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
463
            if (bw4 == 1 && bh4 == ss_ver)
1653
184
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
463
        }
1655
1656
        // chroma prediction
1657
7.46k
        if (is_sub8x8) {
1658
458
            assert(ss_hor == 1);
1659
458
            ptrdiff_t h_off = 0, v_off = 0;
1660
458
            if (bw4 == 1 && bh4 == ss_ver) {
1661
549
                for (int pl = 0; pl < 2; pl++) {
1662
366
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
366
                             NULL, f->cur.stride[1],
1664
366
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
366
                             r[-1][t->bx - 1].mv.mv[0],
1666
366
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
366
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
366
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
366
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
366
                    if (res) return res;
1671
366
                }
1672
183
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
183
                h_off = 2;
1674
183
            }
1675
458
            if (bw4 == 1) {
1676
317
                const enum Filter2d left_filter_2d =
1677
317
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
951
                for (int pl = 0; pl < 2; pl++) {
1679
634
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
634
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
634
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
634
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
634
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
634
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
634
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
634
                    if (res) return res;
1687
634
                }
1688
317
                h_off = 2;
1689
317
            }
1690
458
            if (bh4 == ss_ver) {
1691
324
                const enum Filter2d top_filter_2d =
1692
324
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
972
                for (int pl = 0; pl < 2; pl++) {
1694
648
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
648
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
648
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
648
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
648
                             r[-1][t->bx].ref.ref[0] - 1,
1699
648
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
648
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
648
                    if (res) return res;
1702
648
                }
1703
324
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
324
            }
1705
1.37k
            for (int pl = 0; pl < 2; pl++) {
1706
916
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
916
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
916
                         refp, b->ref[0], filter_2d);
1709
916
                if (res) return res;
1710
916
            }
1711
7.00k
        } else {
1712
7.00k
            if (imin(cbw4, cbh4) > 1 &&
1713
4.24k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
3.78k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
555
            {
1716
1.66k
                for (int pl = 0; pl < 2; pl++) {
1717
1.11k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
1.11k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
1.11k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
1.11k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
1.11k
                    if (res) return res;
1722
1.11k
                }
1723
6.45k
            } else {
1724
19.3k
                for (int pl = 0; pl < 2; pl++) {
1725
12.9k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
12.9k
                             NULL, f->cur.stride[1],
1727
12.9k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
12.9k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
12.9k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
12.9k
                    if (res) return res;
1731
12.9k
                    if (b->motion_mode == MM_OBMC) {
1732
3.06k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
3.06k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
3.06k
                        if (res) return res;
1735
3.06k
                    }
1736
12.9k
                }
1737
6.45k
            }
1738
7.00k
            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
374
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
1.12k
                for (int pl = 0; pl < 2; pl++) {
1745
748
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
748
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
748
                    enum IntraPredMode m =
1748
748
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
590
                        SMOOTH_PRED : b->interintra_mode;
1750
748
                    int angle = 0;
1751
748
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
748
                    const pixel *top_sb_edge = NULL;
1753
748
                    if (!(t->by & (f->sb_step - 1))) {
1754
128
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
128
                        const int sby = t->by >> f->sb_shift;
1756
128
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
128
                    }
1758
748
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
748
                                                          (t->bx >> ss_hor) >
1760
748
                                                              (ts->tiling.col_start >> ss_hor),
1761
748
                                                          t->by >> ss_ver,
1762
748
                                                          (t->by >> ss_ver) >
1763
748
                                                              (ts->tiling.row_start >> ss_ver),
1764
748
                                                          ts->tiling.col_end >> ss_hor,
1765
748
                                                          ts->tiling.row_end >> ss_ver,
1766
748
                                                          0, uvdst, f->cur.stride[1],
1767
748
                                                          top_sb_edge, m,
1768
748
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
748
                                                          HIGHBD_CALL_SUFFIX);
1770
748
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
748
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
748
                                             HIGHBD_CALL_SUFFIX);
1773
748
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
748
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
748
                }
1776
374
            }
1777
7.00k
        }
1778
1779
9.03k
    skip_inter_chroma_pred: {}
1780
9.03k
        t->tl_4x4_filter = filter_2d;
1781
9.03k
    } else {
1782
1.80k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
1.80k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
1.80k
        int jnt_weight;
1786
1.80k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
1.80k
        const uint8_t *mask;
1788
1789
5.40k
        for (int i = 0; i < 2; i++) {
1790
3.60k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
3.60k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
143
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
143
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
143
                if (res) return res;
1796
3.45k
            } else {
1797
3.45k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
3.45k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
3.45k
                if (res) return res;
1800
3.45k
            }
1801
3.60k
        }
1802
1.80k
        switch (b->comp_type) {
1803
1.29k
        case COMP_INTER_AVG:
1804
1.29k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
1.29k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
1.29k
            break;
1807
161
        case COMP_INTER_WEIGHTED_AVG:
1808
161
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
161
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
161
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
161
            break;
1812
228
        case COMP_INTER_SEG:
1813
228
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
228
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
228
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
228
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
228
            mask = seg_mask;
1818
228
            break;
1819
120
        case COMP_INTER_WEDGE:
1820
120
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
120
            dsp->mc.mask(dst, f->cur.stride[0],
1822
120
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
120
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
120
            if (has_chroma)
1825
105
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
120
            break;
1827
1.80k
        }
1828
1829
        // chroma
1830
4.95k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
9.90k
            for (int i = 0; i < 2; i++) {
1832
6.60k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
6.60k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
900
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
222
                {
1836
222
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
222
                                      b_dim, 1 + pl,
1838
222
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
222
                    if (res) return res;
1840
6.38k
                } else {
1841
6.38k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
6.38k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
6.38k
                    if (res) return res;
1844
6.38k
                }
1845
6.60k
            }
1846
3.30k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
3.30k
            switch (b->comp_type) {
1848
2.42k
            case COMP_INTER_AVG:
1849
2.42k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
2.42k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
2.42k
                            HIGHBD_CALL_SUFFIX);
1852
2.42k
                break;
1853
264
            case COMP_INTER_WEIGHTED_AVG:
1854
264
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
264
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
264
                              HIGHBD_CALL_SUFFIX);
1857
264
                break;
1858
210
            case COMP_INTER_WEDGE:
1859
610
            case COMP_INTER_SEG:
1860
610
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
610
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
610
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
610
                             HIGHBD_CALL_SUFFIX);
1864
610
                break;
1865
3.30k
            }
1866
3.30k
        }
1867
1.80k
    }
1868
1869
27.2k
    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
27.2k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
27.2k
    if (b->skip) {
1882
        // reset coef contexts
1883
15.6k
        BlockContext *const a = t->a;
1884
15.6k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
15.6k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
15.6k
        if (has_chroma) {
1887
13.8k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
13.8k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
13.8k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
13.8k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
13.8k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
13.8k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
13.8k
        }
1894
15.6k
        return 0;
1895
15.6k
    }
1896
1897
11.6k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
11.6k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
11.6k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
23.4k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
23.7k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
11.9k
            int y_off = !!init_y, y;
1905
11.9k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
25.0k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
13.1k
                 y += ytx->h, y_off++)
1908
13.1k
            {
1909
13.1k
                int x, x_off = !!init_x;
1910
28.2k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
15.1k
                     x += ytx->w, x_off++)
1912
15.1k
                {
1913
15.1k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
15.1k
                                   x_off, y_off, &dst[x * 4]);
1915
15.1k
                    t->bx += ytx->w;
1916
15.1k
                }
1917
13.1k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
13.1k
                t->bx -= x;
1919
13.1k
                t->by += ytx->h;
1920
13.1k
            }
1921
11.9k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
11.9k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
32.9k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
21.9k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
21.9k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
21.9k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
46.9k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
24.9k
                {
1931
24.9k
                    int x;
1932
24.9k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
53.5k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
28.5k
                    {
1935
28.5k
                        coef *cf;
1936
28.5k
                        int eob;
1937
28.5k
                        enum TxfmType txtp;
1938
28.5k
                        if (t->frame_thread.pass) {
1939
28.5k
                            const int p = t->frame_thread.pass & 1;
1940
28.5k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
28.5k
                            cf = ts->frame_thread[p].cf;
1942
28.5k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
28.5k
                            eob  = cbi >> 5;
1944
28.5k
                            txtp = cbi & 0x1f;
1945
28.5k
                        } else {
1946
0
                            uint8_t cf_ctx;
1947
0
                            cf = bitfn(t->cf);
1948
0
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
0
                                                        bx4 + (x << ss_hor)];
1950
0
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
0
                                               &t->l.ccoef[pl][cby4 + y],
1952
0
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
0
                                               cf, &txtp, &cf_ctx);
1954
0
                            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
0
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
0
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
0
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
0
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
0
                        }
1963
28.5k
                        if (eob >= 0) {
1964
9.01k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
9.01k
                            dsp->itx.itxfm_add[b->uvtx]
1967
9.01k
                                              [txtp](&uvdst[4 * x],
1968
9.01k
                                                     f->cur.stride[1],
1969
9.01k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
9.01k
                            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
9.01k
                        }
1974
28.5k
                        t->bx += uvtx->w << ss_hor;
1975
28.5k
                    }
1976
24.9k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
24.9k
                    t->bx -= x << ss_hor;
1978
24.9k
                    t->by += uvtx->h << ss_ver;
1979
24.9k
                }
1980
21.9k
                t->by -= y << ss_ver;
1981
21.9k
            }
1982
11.9k
        }
1983
11.8k
    }
1984
11.6k
    return 0;
1985
27.2k
}
1986
1987
26.2k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
26.2k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
26.2k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
26.2k
    const int y = sby * f->sb_step * 4;
1994
26.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
26.2k
    pixel *const p[3] = {
1996
26.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
26.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
26.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
26.2k
    };
2000
26.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
26.2k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
26.2k
                                        f->lf.start_of_tile_row[sby]);
2003
26.2k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
12.9k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
12.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
12.9k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
12.9k
    const int y = sby * f->sb_step * 4;
1994
12.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
12.9k
    pixel *const p[3] = {
1996
12.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
12.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
12.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
12.9k
    };
2000
12.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
12.9k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
12.9k
                                        f->lf.start_of_tile_row[sby]);
2003
12.9k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
13.2k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
13.2k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
13.2k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
13.2k
    const int y = sby * f->sb_step * 4;
1994
13.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
13.2k
    pixel *const p[3] = {
1996
13.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
13.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
13.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
13.2k
    };
2000
13.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
13.2k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
13.2k
                                        f->lf.start_of_tile_row[sby]);
2003
13.2k
}
2004
2005
40.2k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
40.2k
    const int y = sby * f->sb_step * 4;
2007
40.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
40.2k
    pixel *const p[3] = {
2009
40.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
40.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
40.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
40.2k
    };
2013
40.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
40.2k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
40.2k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
26.1k
    {
2017
26.1k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
26.1k
    }
2019
40.2k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
33.5k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
33.5k
    }
2023
40.2k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
18.6k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
18.6k
    const int y = sby * f->sb_step * 4;
2007
18.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
18.6k
    pixel *const p[3] = {
2009
18.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
18.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
18.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
18.6k
    };
2013
18.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
18.6k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
18.6k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
12.9k
    {
2017
12.9k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
12.9k
    }
2019
18.6k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
14.9k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
14.9k
    }
2023
18.6k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
21.5k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
21.5k
    const int y = sby * f->sb_step * 4;
2007
21.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
21.5k
    pixel *const p[3] = {
2009
21.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
21.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
21.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
21.5k
    };
2013
21.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
21.5k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
21.5k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
13.2k
    {
2017
13.2k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
13.2k
    }
2019
21.5k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
18.6k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
18.6k
    }
2023
21.5k
}
2024
2025
24.5k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
24.5k
    const Dav1dFrameContext *const f = tc->f;
2027
24.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
24.5k
    const int sbsz = f->sb_step;
2029
24.5k
    const int y = sby * sbsz * 4;
2030
24.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
24.5k
    pixel *const p[3] = {
2032
24.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
24.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
24.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
24.5k
    };
2036
24.5k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
24.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
24.5k
    const int start = sby * sbsz;
2039
24.5k
    if (sby) {
2040
18.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
18.8k
        pixel *p_up[3] = {
2042
18.8k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
18.8k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
18.8k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
18.8k
        };
2046
18.8k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
18.8k
    }
2048
24.5k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
24.5k
    const int end = imin(start + n_blks, f->bh);
2050
24.5k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
24.5k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
10.6k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
10.6k
    const Dav1dFrameContext *const f = tc->f;
2027
10.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
10.6k
    const int sbsz = f->sb_step;
2029
10.6k
    const int y = sby * sbsz * 4;
2030
10.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
10.6k
    pixel *const p[3] = {
2032
10.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
10.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
10.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
10.6k
    };
2036
10.6k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
10.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
10.6k
    const int start = sby * sbsz;
2039
10.6k
    if (sby) {
2040
7.87k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
7.87k
        pixel *p_up[3] = {
2042
7.87k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
7.87k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
7.87k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
7.87k
        };
2046
7.87k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
7.87k
    }
2048
10.6k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
10.6k
    const int end = imin(start + n_blks, f->bh);
2050
10.6k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
10.6k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
13.8k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
13.8k
    const Dav1dFrameContext *const f = tc->f;
2027
13.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
13.8k
    const int sbsz = f->sb_step;
2029
13.8k
    const int y = sby * sbsz * 4;
2030
13.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
13.8k
    pixel *const p[3] = {
2032
13.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
13.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
13.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
13.8k
    };
2036
13.8k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
13.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
13.8k
    const int start = sby * sbsz;
2039
13.8k
    if (sby) {
2040
10.9k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
10.9k
        pixel *p_up[3] = {
2042
10.9k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
10.9k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
10.9k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
10.9k
        };
2046
10.9k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
10.9k
    }
2048
13.8k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
13.8k
    const int end = imin(start + n_blks, f->bh);
2050
13.8k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
13.8k
}
2052
2053
4.18k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
4.18k
    const int sbsz = f->sb_step;
2055
4.18k
    const int y = sby * sbsz * 4;
2056
4.18k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
4.18k
    const pixel *const p[3] = {
2058
4.18k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
4.18k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
4.18k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
4.18k
    };
2062
4.18k
    pixel *const sr_p[3] = {
2063
4.18k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
4.18k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
4.18k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
4.18k
    };
2067
4.18k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
14.8k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
10.6k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
10.6k
        const int h_start = 8 * !!sby >> ss_ver;
2071
10.6k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
10.6k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
10.6k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
10.6k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
10.6k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
10.6k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
10.6k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
10.6k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
10.6k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
10.6k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
10.6k
                          imin(img_h, h_end) + h_start, src_w,
2083
10.6k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
10.6k
                          HIGHBD_CALL_SUFFIX);
2085
10.6k
    }
2086
4.18k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
2.01k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
2.01k
    const int sbsz = f->sb_step;
2055
2.01k
    const int y = sby * sbsz * 4;
2056
2.01k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
2.01k
    const pixel *const p[3] = {
2058
2.01k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
2.01k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
2.01k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
2.01k
    };
2062
2.01k
    pixel *const sr_p[3] = {
2063
2.01k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
2.01k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
2.01k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
2.01k
    };
2067
2.01k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
7.36k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
5.35k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
5.35k
        const int h_start = 8 * !!sby >> ss_ver;
2071
5.35k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
5.35k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
5.35k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
5.35k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
5.35k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
5.35k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
5.35k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
5.35k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
5.35k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
5.35k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
5.35k
                          imin(img_h, h_end) + h_start, src_w,
2083
5.35k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
5.35k
                          HIGHBD_CALL_SUFFIX);
2085
5.35k
    }
2086
2.01k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
2.17k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
2.17k
    const int sbsz = f->sb_step;
2055
2.17k
    const int y = sby * sbsz * 4;
2056
2.17k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
2.17k
    const pixel *const p[3] = {
2058
2.17k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
2.17k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
2.17k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
2.17k
    };
2062
2.17k
    pixel *const sr_p[3] = {
2063
2.17k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
2.17k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
2.17k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
2.17k
    };
2067
2.17k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
7.46k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
5.29k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
5.29k
        const int h_start = 8 * !!sby >> ss_ver;
2071
5.29k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
5.29k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
5.29k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
5.29k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
5.29k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
5.29k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
5.29k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
5.29k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
5.29k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
5.29k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
5.29k
                          imin(img_h, h_end) + h_start, src_w,
2083
5.29k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
5.29k
                          HIGHBD_CALL_SUFFIX);
2085
5.29k
    }
2086
2.17k
}
2087
2088
15.6k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
15.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
15.6k
    const int y = sby * f->sb_step * 4;
2091
15.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
15.6k
    pixel *const sr_p[3] = {
2093
15.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
15.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
15.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
15.6k
    };
2097
15.6k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
15.6k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
7.72k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
7.72k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
7.72k
    const int y = sby * f->sb_step * 4;
2091
7.72k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
7.72k
    pixel *const sr_p[3] = {
2093
7.72k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
7.72k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
7.72k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
7.72k
    };
2097
7.72k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
7.72k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
7.94k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
7.94k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
7.94k
    const int y = sby * f->sb_step * 4;
2091
7.94k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
7.94k
    pixel *const sr_p[3] = {
2093
7.94k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
7.94k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
7.94k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
7.94k
    };
2097
7.94k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
7.94k
}
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
60.6k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
60.6k
    const Dav1dFrameContext *const f = t->f;
2113
60.6k
    Dav1dTileState *const ts = t->ts;
2114
60.6k
    const int sby = t->by >> f->sb_shift;
2115
60.6k
    const int sby_off = f->sb128w * 128 * sby;
2116
60.6k
    const int x_off = ts->tiling.col_start;
2117
2118
60.6k
    const pixel *const y =
2119
60.6k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
60.6k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
60.6k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
60.6k
               4 * (ts->tiling.col_end - x_off));
2123
2124
60.6k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
51.0k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
51.0k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
51.0k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
51.0k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
153k
        for (int pl = 1; pl <= 2; pl++)
2131
102k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
54.5k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
54.5k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
51.0k
    }
2135
60.6k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
30.9k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
30.9k
    const Dav1dFrameContext *const f = t->f;
2113
30.9k
    Dav1dTileState *const ts = t->ts;
2114
30.9k
    const int sby = t->by >> f->sb_shift;
2115
30.9k
    const int sby_off = f->sb128w * 128 * sby;
2116
30.9k
    const int x_off = ts->tiling.col_start;
2117
2118
30.9k
    const pixel *const y =
2119
30.9k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
30.9k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
30.9k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
30.9k
               4 * (ts->tiling.col_end - x_off));
2123
2124
30.9k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
27.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
27.2k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
27.2k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
27.2k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
81.8k
        for (int pl = 1; pl <= 2; pl++)
2131
54.5k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
54.5k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
54.5k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
27.2k
    }
2135
30.9k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
29.6k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
29.6k
    const Dav1dFrameContext *const f = t->f;
2113
29.6k
    Dav1dTileState *const ts = t->ts;
2114
29.6k
    const int sby = t->by >> f->sb_shift;
2115
29.6k
    const int sby_off = f->sb128w * 128 * sby;
2116
29.6k
    const int x_off = ts->tiling.col_start;
2117
2118
29.6k
    const pixel *const y =
2119
29.6k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
29.6k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
29.6k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
29.6k
               4 * (ts->tiling.col_end - x_off));
2123
2124
29.6k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
23.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
23.7k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
23.7k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
23.7k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
71.2k
        for (int pl = 1; pl <= 2; pl++)
2131
47.4k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
23.7k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
23.7k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
23.7k
    }
2135
29.6k
}
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
3.60k
{
2142
3.60k
    const Dav1dFrameContext *const f = t->f;
2143
3.60k
    pixel *const pal = t->frame_thread.pass ?
2144
3.60k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
3.60k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
3.60k
        bytefn(t->scratch.pal)[0];
2147
17.3k
    for (int x = 0; x < bw4; x++)
2148
13.7k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
16.5k
    for (int y = 0; y < bh4; y++)
2150
12.9k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
3.60k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
1.94k
{
2142
1.94k
    const Dav1dFrameContext *const f = t->f;
2143
1.94k
    pixel *const pal = t->frame_thread.pass ?
2144
1.94k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
1.94k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
1.94k
        bytefn(t->scratch.pal)[0];
2147
9.33k
    for (int x = 0; x < bw4; x++)
2148
7.39k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
8.80k
    for (int y = 0; y < bh4; y++)
2150
6.86k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
1.94k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
1.66k
{
2142
1.66k
    const Dav1dFrameContext *const f = t->f;
2143
1.66k
    pixel *const pal = t->frame_thread.pass ?
2144
1.66k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
1.66k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
1.66k
        bytefn(t->scratch.pal)[0];
2147
8.01k
    for (int x = 0; x < bw4; x++)
2148
6.35k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
7.74k
    for (int y = 0; y < bh4; y++)
2150
6.08k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
1.66k
}
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
1.73k
{
2158
1.73k
    const Dav1dFrameContext *const f = t->f;
2159
1.73k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
1.73k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
1.73k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
1.73k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
5.21k
    for (int pl = 1; pl <= 2; pl++) {
2165
19.3k
        for (int x = 0; x < bw4; x++)
2166
15.8k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
23.0k
        for (int y = 0; y < bh4; y++)
2168
19.5k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
3.47k
    }
2170
1.73k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
1.14k
{
2158
1.14k
    const Dav1dFrameContext *const f = t->f;
2159
1.14k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
1.14k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
1.14k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
1.14k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
3.44k
    for (int pl = 1; pl <= 2; pl++) {
2165
12.1k
        for (int x = 0; x < bw4; x++)
2166
9.89k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
15.9k
        for (int y = 0; y < bh4; y++)
2168
13.6k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
2.29k
    }
2170
1.14k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
590
{
2158
590
    const Dav1dFrameContext *const f = t->f;
2159
590
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
590
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
590
                            ((t->bx >> 1) + (t->by & 1))] :
2162
590
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
1.77k
    for (int pl = 1; pl <= 2; pl++) {
2165
7.17k
        for (int x = 0; x < bw4; x++)
2166
5.99k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
7.07k
        for (int y = 0; y < bh4; y++)
2168
5.89k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
1.18k
    }
2170
590
}
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
5.34k
{
2176
5.34k
    Dav1dTileState *const ts = t->ts;
2177
5.34k
    const Dav1dFrameContext *const f = t->f;
2178
5.34k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
5.34k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
5.34k
    pixel cache[16], used_cache[8];
2181
5.34k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
5.34k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
5.34k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
5.34k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
5.34k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
7.07k
    while (l_cache && a_cache) {
2190
1.72k
        if (*l < *a) {
2191
662
            if (!n_cache || cache[n_cache - 1] != *l)
2192
652
                cache[n_cache++] = *l;
2193
662
            l++;
2194
662
            l_cache--;
2195
1.06k
        } else {
2196
1.06k
            if (*a == *l) {
2197
462
                l++;
2198
462
                l_cache--;
2199
462
            }
2200
1.06k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
1.00k
                cache[n_cache++] = *a;
2202
1.06k
            a++;
2203
1.06k
            a_cache--;
2204
1.06k
        }
2205
1.72k
    }
2206
5.34k
    if (l_cache) {
2207
4.60k
        do {
2208
4.60k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
3.73k
                cache[n_cache++] = *l;
2210
4.60k
            l++;
2211
4.60k
        } while (--l_cache > 0);
2212
4.29k
    } else if (a_cache) {
2213
4.30k
        do {
2214
4.30k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
3.39k
                cache[n_cache++] = *a;
2216
4.30k
            a++;
2217
4.30k
        } while (--a_cache > 0);
2218
1.02k
    }
2219
2220
    // find reused cache entries
2221
5.34k
    int i = 0;
2222
13.2k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
7.92k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
3.89k
            used_cache[i++] = cache[n];
2225
5.34k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
5.34k
    pixel *const pal = t->frame_thread.pass ?
2229
5.34k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
5.34k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
5.34k
        bytefn(t->scratch.pal)[pl];
2232
5.34k
    if (i < pal_sz) {
2233
4.88k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
4.88k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
4.88k
        if (i < pal_sz) {
2237
4.56k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
4.56k
            const int max = (1 << bpc) - 1;
2239
2240
10.9k
            do {
2241
10.9k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
10.9k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
10.9k
                if (prev + !pl >= max) {
2244
6.53k
                    for (; i < pal_sz; i++)
2245
4.28k
                        pal[i] = max;
2246
2.24k
                    break;
2247
2.24k
                }
2248
8.69k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
8.69k
            } while (i < pal_sz);
2250
4.56k
        }
2251
2252
        // merge cache+new entries
2253
4.88k
        int n = 0, m = n_used_cache;
2254
27.6k
        for (i = 0; i < pal_sz; i++) {
2255
22.7k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
2.67k
                pal[i] = used_cache[n++];
2257
20.1k
            } else {
2258
20.1k
                assert(m < pal_sz);
2259
20.1k
                pal[i] = pal[m++];
2260
20.1k
            }
2261
22.7k
        }
2262
4.88k
    } else {
2263
458
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
458
    }
2265
2266
5.34k
    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
5.34k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
3.09k
{
2176
3.09k
    Dav1dTileState *const ts = t->ts;
2177
3.09k
    const Dav1dFrameContext *const f = t->f;
2178
3.09k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
3.09k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
3.09k
    pixel cache[16], used_cache[8];
2181
3.09k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
3.09k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
3.09k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
3.09k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
3.09k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
4.10k
    while (l_cache && a_cache) {
2190
1.01k
        if (*l < *a) {
2191
378
            if (!n_cache || cache[n_cache - 1] != *l)
2192
371
                cache[n_cache++] = *l;
2193
378
            l++;
2194
378
            l_cache--;
2195
639
        } else {
2196
639
            if (*a == *l) {
2197
274
                l++;
2198
274
                l_cache--;
2199
274
            }
2200
639
            if (!n_cache || cache[n_cache - 1] != *a)
2201
604
                cache[n_cache++] = *a;
2202
639
            a++;
2203
639
            a_cache--;
2204
639
        }
2205
1.01k
    }
2206
3.09k
    if (l_cache) {
2207
2.65k
        do {
2208
2.65k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
2.16k
                cache[n_cache++] = *l;
2210
2.65k
            l++;
2211
2.65k
        } while (--l_cache > 0);
2212
2.48k
    } else if (a_cache) {
2213
2.50k
        do {
2214
2.50k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
1.98k
                cache[n_cache++] = *a;
2216
2.50k
            a++;
2217
2.50k
        } while (--a_cache > 0);
2218
602
    }
2219
2220
    // find reused cache entries
2221
3.09k
    int i = 0;
2222
7.70k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
4.61k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
2.27k
            used_cache[i++] = cache[n];
2225
3.09k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
3.09k
    pixel *const pal = t->frame_thread.pass ?
2229
3.09k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
3.09k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
3.09k
        bytefn(t->scratch.pal)[pl];
2232
3.09k
    if (i < pal_sz) {
2233
2.82k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
2.82k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
2.82k
        if (i < pal_sz) {
2237
2.64k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
2.64k
            const int max = (1 << bpc) - 1;
2239
2240
6.22k
            do {
2241
6.22k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
6.22k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
6.22k
                if (prev + !pl >= max) {
2244
3.87k
                    for (; i < pal_sz; i++)
2245
2.55k
                        pal[i] = max;
2246
1.31k
                    break;
2247
1.31k
                }
2248
4.90k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
4.90k
            } while (i < pal_sz);
2250
2.64k
        }
2251
2252
        // merge cache+new entries
2253
2.82k
        int n = 0, m = n_used_cache;
2254
15.9k
        for (i = 0; i < pal_sz; i++) {
2255
13.1k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
1.53k
                pal[i] = used_cache[n++];
2257
11.5k
            } else {
2258
11.5k
                assert(m < pal_sz);
2259
11.5k
                pal[i] = pal[m++];
2260
11.5k
            }
2261
13.1k
        }
2262
2.82k
    } else {
2263
271
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
271
    }
2265
2266
3.09k
    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
3.09k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
2.25k
{
2176
2.25k
    Dav1dTileState *const ts = t->ts;
2177
2.25k
    const Dav1dFrameContext *const f = t->f;
2178
2.25k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
2.25k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
2.25k
    pixel cache[16], used_cache[8];
2181
2.25k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
2.25k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
2.25k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
2.25k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
2.25k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
2.96k
    while (l_cache && a_cache) {
2190
710
        if (*l < *a) {
2191
284
            if (!n_cache || cache[n_cache - 1] != *l)
2192
281
                cache[n_cache++] = *l;
2193
284
            l++;
2194
284
            l_cache--;
2195
426
        } else {
2196
426
            if (*a == *l) {
2197
188
                l++;
2198
188
                l_cache--;
2199
188
            }
2200
426
            if (!n_cache || cache[n_cache - 1] != *a)
2201
400
                cache[n_cache++] = *a;
2202
426
            a++;
2203
426
            a_cache--;
2204
426
        }
2205
710
    }
2206
2.25k
    if (l_cache) {
2207
1.95k
        do {
2208
1.95k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
1.56k
                cache[n_cache++] = *l;
2210
1.95k
            l++;
2211
1.95k
        } while (--l_cache > 0);
2212
1.80k
    } else if (a_cache) {
2213
1.80k
        do {
2214
1.80k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
1.40k
                cache[n_cache++] = *a;
2216
1.80k
            a++;
2217
1.80k
        } while (--a_cache > 0);
2218
425
    }
2219
2220
    // find reused cache entries
2221
2.25k
    int i = 0;
2222
5.57k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
3.31k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
1.62k
            used_cache[i++] = cache[n];
2225
2.25k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
2.25k
    pixel *const pal = t->frame_thread.pass ?
2229
2.25k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
2.25k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
2.25k
        bytefn(t->scratch.pal)[pl];
2232
2.25k
    if (i < pal_sz) {
2233
2.06k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
2.06k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
2.06k
        if (i < pal_sz) {
2237
1.92k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
1.92k
            const int max = (1 << bpc) - 1;
2239
2240
4.71k
            do {
2241
4.71k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
4.71k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
4.71k
                if (prev + !pl >= max) {
2244
2.65k
                    for (; i < pal_sz; i++)
2245
1.73k
                        pal[i] = max;
2246
925
                    break;
2247
925
                }
2248
3.79k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
3.79k
            } while (i < pal_sz);
2250
1.92k
        }
2251
2252
        // merge cache+new entries
2253
2.06k
        int n = 0, m = n_used_cache;
2254
11.7k
        for (i = 0; i < pal_sz; i++) {
2255
9.65k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
1.14k
                pal[i] = used_cache[n++];
2257
8.51k
            } else {
2258
8.51k
                assert(m < pal_sz);
2259
8.51k
                pal[i] = pal[m++];
2260
8.51k
            }
2261
9.65k
        }
2262
2.06k
    } else {
2263
187
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
187
    }
2265
2266
2.25k
    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
2.25k
}
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
1.73k
{
2281
1.73k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
1.73k
    Dav1dTileState *const ts = t->ts;
2285
1.73k
    const Dav1dFrameContext *const f = t->f;
2286
1.73k
    pixel *const pal = t->frame_thread.pass ?
2287
1.73k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
1.73k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
1.73k
        bytefn(t->scratch.pal)[2];
2290
1.73k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
1.73k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
923
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
923
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
923
        const int max = (1 << bpc) - 1;
2295
4.02k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
3.10k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
3.10k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
3.10k
            prev = pal[i] = (prev + delta) & max;
2299
3.10k
        }
2300
923
    } else {
2301
4.30k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
3.48k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
816
    }
2304
1.73k
    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
1.73k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
1.14k
{
2281
1.14k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
1.14k
    Dav1dTileState *const ts = t->ts;
2285
1.14k
    const Dav1dFrameContext *const f = t->f;
2286
1.14k
    pixel *const pal = t->frame_thread.pass ?
2287
1.14k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
1.14k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
1.14k
        bytefn(t->scratch.pal)[2];
2290
1.14k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
1.14k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
626
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
626
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
626
        const int max = (1 << bpc) - 1;
2295
2.71k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
2.09k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
2.09k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
2.09k
            prev = pal[i] = (prev + delta) & max;
2299
2.09k
        }
2300
626
    } else {
2301
2.74k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
2.22k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
523
    }
2304
1.14k
    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
1.14k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
590
{
2281
590
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
590
    Dav1dTileState *const ts = t->ts;
2285
590
    const Dav1dFrameContext *const f = t->f;
2286
590
    pixel *const pal = t->frame_thread.pass ?
2287
590
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
590
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
590
        bytefn(t->scratch.pal)[2];
2290
590
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
590
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
297
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
297
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
297
        const int max = (1 << bpc) - 1;
2295
1.31k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
1.01k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
1.01k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
1.01k
            prev = pal[i] = (prev + delta) & max;
2299
1.01k
        }
2300
297
    } else {
2301
1.56k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
1.26k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
293
    }
2304
590
    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
590
}