Coverage Report

Created: 2026-10-17 06:50

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