Coverage Report

Created: 2026-07-16 06:31

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
409k
static inline unsigned read_golomb(MsacContext *const msac) {
50
409k
    int len = 0;
51
409k
    unsigned val = 1;
52
53
685k
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
685k
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
409k
    return val - 1;
57
409k
}
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
4.38M
{
66
4.38M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
4.38M
    if (chroma) {
69
2.05M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
2.05M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
2.05M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.16M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
2.05M
        unsigned ca, cl;
74
75
2.05M
#define MERGE_CTX(dir, type, no_val) \
76
4.10M
        c##dir = *(const type *) dir != no_val; \
77
4.10M
        break
78
79
2.05M
        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
602k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
363k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
358k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
728k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
2.05M
        }
91
2.05M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
676k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
400k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
270k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
704k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
2.05M
        }
98
2.05M
#undef MERGE_CTX
99
100
2.05M
        return 7 + not_one_blk * 3 + ca + cl;
101
2.32M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
591k
        return 0;
103
1.73M
    } else {
104
1.73M
        unsigned la, ll;
105
106
1.73M
#define MERGE_CTX(dir, type, tx) \
107
3.49M
        if (tx == TX_64X64) { \
108
191k
            uint64_t tmp = *(const uint64_t *) dir; \
109
191k
            tmp |= *(const uint64_t *) &dir[8]; \
110
191k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
191k
        } else \
112
3.49M
            l##dir = *(const type *) dir; \
113
3.49M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
3.49M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
3.49M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
3.49M
        break
117
118
1.73M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
1.25M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
211k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
168k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
16.9k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
95.9k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.73M
        }
126
1.74M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
1.26M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
204k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
167k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
17.3k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
95.9k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.74M
        }
134
1.74M
#undef MERGE_CTX
135
136
1.74M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.74M
    }
138
4.38M
}
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
2.17M
{
144
2.17M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
2.17M
    int s;
146
147
2.17M
#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
2.17M
    __asm__("" : "+r"(mask), "+r"(mul));
151
2.17M
#endif
152
153
2.17M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
1.20M
    case TX_4X4: {
156
1.20M
        int t = *(const uint8_t *) a >> 6;
157
1.20M
        t    += *(const uint8_t *) l >> 6;
158
1.20M
        s = t - 1 - 1;
159
1.20M
        break;
160
0
    }
161
152k
    case TX_8X8: {
162
152k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
152k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
152k
        t *= 0x04040404U;
165
152k
        s = (int) (t >> 24) - 2 - 2;
166
152k
        break;
167
0
    }
168
124k
    case TX_16X16: {
169
124k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
124k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
124k
        t *= (uint32_t) mul;
172
124k
        s = (int) (t >> 24) - 4 - 4;
173
124k
        break;
174
0
    }
175
177k
    case TX_32X32: {
176
177k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
177k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
177k
        t *= mul;
179
177k
        s = (int) (t >> 56) - 8 - 8;
180
177k
        break;
181
0
    }
182
82.5k
    case TX_64X64: {
183
82.5k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
82.5k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
82.5k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
82.5k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
82.5k
        t *= mul;
188
82.5k
        s = (int) (t >> 56) - 16 - 16;
189
82.5k
        break;
190
0
    }
191
42.3k
    case RTX_4X8: {
192
42.3k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
42.3k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
42.3k
        t *= 0x04040404U;
195
42.3k
        s = (int) (t >> 24) - 1 - 2;
196
42.3k
        break;
197
0
    }
198
60.3k
    case RTX_8X4: {
199
60.3k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
60.3k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
60.3k
        t *= 0x04040404U;
202
60.3k
        s = (int) (t >> 24) - 2 - 1;
203
60.3k
        break;
204
0
    }
205
40.8k
    case RTX_8X16: {
206
40.8k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
40.8k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
40.8k
        t = (t >> 6) * (uint32_t) mul;
209
40.8k
        s = (int) (t >> 24) - 2 - 4;
210
40.8k
        break;
211
0
    }
212
79.1k
    case RTX_16X8: {
213
79.1k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
79.1k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
79.1k
        t = (t >> 6) * (uint32_t) mul;
216
79.1k
        s = (int) (t >> 24) - 4 - 2;
217
79.1k
        break;
218
0
    }
219
27.3k
    case RTX_16X32: {
220
27.3k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
27.3k
        t         += *(const uint64_t *) l & mask;
222
27.3k
        t = (t >> 6) * mul;
223
27.3k
        s = (int) (t >> 56) - 4 - 8;
224
27.3k
        break;
225
0
    }
226
43.1k
    case RTX_32X16: {
227
43.1k
        uint64_t t = *(const uint64_t *) a & mask;
228
43.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
43.1k
        t = (t >> 6) * mul;
230
43.1k
        s = (int) (t >> 56) - 8 - 4;
231
43.1k
        break;
232
0
    }
233
13.5k
    case RTX_32X64: {
234
13.5k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
13.5k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
13.5k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
13.5k
        t *= mul;
238
13.5k
        s = (int) (t >> 56) - 8 - 16;
239
13.5k
        break;
240
0
    }
241
16.1k
    case RTX_64X32: {
242
16.1k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
16.1k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
16.1k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
16.1k
        t *= mul;
246
16.1k
        s = (int) (t >> 56) - 16 - 8;
247
16.1k
        break;
248
0
    }
249
20.6k
    case RTX_4X16: {
250
20.6k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
20.6k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
20.6k
        t = (t >> 6) * (uint32_t) mul;
253
20.6k
        s = (int) (t >> 24) - 1 - 4;
254
20.6k
        break;
255
0
    }
256
42.5k
    case RTX_16X4: {
257
42.5k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
42.5k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
42.5k
        t = (t >> 6) * (uint32_t) mul;
260
42.5k
        s = (int) (t >> 24) - 4 - 1;
261
42.5k
        break;
262
0
    }
263
14.4k
    case RTX_8X32: {
264
14.4k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
14.4k
        t         += *(const uint64_t *) l & mask;
266
14.4k
        t = (t >> 6) * mul;
267
14.4k
        s = (int) (t >> 56) - 2 - 8;
268
14.4k
        break;
269
0
    }
270
20.1k
    case RTX_32X8: {
271
20.1k
        uint64_t t = *(const uint64_t *) a & mask;
272
20.1k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
20.1k
        t = (t >> 6) * mul;
274
20.1k
        s = (int) (t >> 56) - 8 - 2;
275
20.1k
        break;
276
0
    }
277
5.80k
    case RTX_16X64: {
278
5.80k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
5.80k
        t         += *(const uint64_t *) &l[0] & mask;
280
5.80k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
5.80k
        t *= mul;
282
5.80k
        s = (int) (t >> 56) - 4 - 16;
283
5.80k
        break;
284
0
    }
285
3.64k
    case RTX_64X16: {
286
3.64k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
3.64k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
3.64k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
3.64k
        t *= mul;
290
3.64k
        s = (int) (t >> 56) - 16 - 4;
291
3.64k
        break;
292
0
    }
293
2.17M
    }
294
295
2.17M
    return (s != 0) + (s > 0);
296
2.17M
}
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
33.4M
{
305
33.4M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
33.4M
    unsigned offset;
307
33.4M
    if (tx_class == TX_CLASS_2D) {
308
31.6M
        mag += levels[1 * stride + 1];
309
31.6M
        *hi_mag = mag;
310
31.6M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
31.6M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
31.6M
    } else {
313
1.74M
        mag += levels[0 * stride + 2];
314
1.74M
        *hi_mag = mag;
315
1.74M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
1.74M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
1.74M
    }
318
33.4M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
33.4M
}
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
4.37M
{
328
4.37M
    Dav1dTileState *const ts = t->ts;
329
4.37M
    const int chroma = !!plane;
330
4.37M
    const Dav1dFrameContext *const f = t->f;
331
4.37M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
4.37M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
4.37M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
4.37M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
4.37M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
4.37M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
4.37M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
4.37M
    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
4.37M
    if (all_skip) {
346
1.93M
        *res_ctx = 0x40;
347
1.93M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
1.93M
        return -1;
349
1.93M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
2.44M
    if (lossless) {
353
1.16M
        assert(t_dim->max == TX_4X4);
354
1.16M
        *txtp = WHT_WHT;
355
1.28M
    } else if (t_dim->max + intra >= TX_64X64) {
356
407k
        *txtp = DCT_DCT;
357
873k
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
232k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
232k
                        get_uv_inter_txtp(t_dim, *txtp);
361
641k
    } 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
12.0k
        *txtp = DCT_DCT;
366
629k
    } else {
367
629k
        unsigned idx;
368
629k
        if (intra) {
369
456k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
397k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
456k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
215k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
215k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
215k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
241k
            } else {
376
241k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
241k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
241k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
241k
            }
380
456k
            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
456k
        } else {
384
172k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
53.5k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
53.5k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
53.5k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
119k
            } else if (t_dim->min == TX_16X16) {
389
16.7k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
16.7k
                          ts->cdf.m.txtp_inter2, 11);
391
16.7k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
102k
            } else {
393
102k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
102k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
102k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
102k
            }
397
172k
            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
172k
        }
401
629k
    }
402
403
    // find end-of-block (eob)
404
2.44M
    int eob;
405
2.44M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
2.44M
    const int tx2dszctx = slw + slh;
407
2.44M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
2.44M
    const int is_1d = tx_class != TX_CLASS_2D;
409
2.44M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
2.45M
    case sz: { \
412
2.45M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
2.45M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
2.45M
        break; \
415
2.45M
    }
416
1.29M
    case_sz(0,   16,  8, [is_1d]);
417
132k
    case_sz(1,   32,  8, [is_1d]);
418
273k
    case_sz(2,   64,  8, [is_1d]);
419
152k
    case_sz(3,  128,  8, [is_1d]);
420
199k
    case_sz(4,  256, 16, [is_1d]);
421
90.9k
    case_sz(5,  512, 16,        );
422
305k
    case_sz(6, 1024, 16,        );
423
2.44M
#undef case_sz
424
2.44M
    }
425
2.44M
    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
2.44M
    if (eob > 1) {
429
1.12M
        const int eob_bin = eob - 2;
430
1.12M
        uint16_t *const eob_hi_bit_cdf =
431
1.12M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.12M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.12M
        if (dbg)
434
0
            printf("Post-eob_hi_bit[%d][%d][%d][%d]: r=%d\n",
435
0
                   t_dim->ctx, chroma, eob_bin, eob_hi_bit, ts->msac.rng);
436
1.12M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.12M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.12M
    }
440
2.44M
    assert(eob >= 0);
441
442
    // base tokens
443
2.44M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
2.44M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
2.44M
    unsigned rc, dc_tok;
446
447
2.44M
    if (eob) {
448
1.19M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.19M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.19M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.19M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.19M
        int tok = eob_tok + 1;
455
1.19M
        int level_tok = tok * 0x41;
456
1.19M
        unsigned mag;
457
458
1.19M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.19M
        unsigned x, y; \
460
1.19M
        uint8_t *level; \
461
1.19M
        if (tx_class == TX_CLASS_2D) \
462
1.19M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.19M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
85.3k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
85.3k
        else /* tx_class == TX_CLASS_V */ \
467
85.3k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.19M
        if (dbg) \
469
1.19M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
1.19M
        if (eob_tok == 2) { \
472
29.4k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
29.4k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
29.4k
            level_tok = tok + (3 << 6); \
475
29.4k
            if (dbg) \
476
29.4k
                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
29.4k
        } \
480
1.19M
        cf[rc] = tok << 11; \
481
1.19M
        if (tx_class == TX_CLASS_2D) \
482
1.19M
            level = levels + rc; \
483
1.19M
        else \
484
1.19M
            level = levels + x * stride + y; \
485
1.19M
        *level = (uint8_t) level_tok; \
486
34.5M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
33.3M
            unsigned rc_i; \
488
33.3M
            if (tx_class == TX_CLASS_2D) \
489
33.3M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
33.3M
            else if (tx_class == TX_CLASS_H) \
491
1.74M
                x = i & mask, y = i >> shift, rc_i = i; \
492
1.74M
            else /* tx_class == TX_CLASS_V */ \
493
1.74M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
33.3M
            assert(x < 32 && y < 32); \
495
33.3M
            if (tx_class == TX_CLASS_2D) \
496
33.3M
                level = levels + rc_i; \
497
33.3M
            else \
498
33.3M
                level = levels + x * stride + y; \
499
33.3M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
33.3M
            if (tx_class == TX_CLASS_2D) \
501
33.3M
                y |= x; \
502
33.3M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
33.3M
            if (dbg) \
504
33.3M
                printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
505
0
                       t_dim->ctx, chroma, ctx, i, rc_i, tok, ts->msac.rng); \
506
33.3M
            if (tok == 3) { \
507
2.67M
                mag &= 63; \
508
2.67M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
2.67M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
2.67M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
2.67M
                if (dbg) \
512
2.67M
                    printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
513
0
                           imin(t_dim->ctx, 3), chroma, ctx, i, rc_i, tok, \
514
0
                           ts->msac.rng); \
515
2.67M
                *level = (uint8_t) (tok + (3 << 6)); \
516
2.67M
                cf[rc_i] = (tok << 11) | rc; \
517
2.67M
                rc = rc_i; \
518
30.7M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
30.7M
                tok *= 0x17ff41; \
521
30.7M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
30.7M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
30.7M
                if (tok) rc = rc_i; \
525
30.7M
                cf[rc_i] = tok; \
526
30.7M
            } \
527
33.3M
        } \
528
        /* dc */ \
529
1.19M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.19M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.19M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.19M
        if (dbg) \
533
1.19M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
1.19M
        if (dc_tok == 3) { \
536
466k
            if (tx_class == TX_CLASS_2D) \
537
466k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
456k
                      levels[1 * stride + 1]; \
539
466k
            mag &= 63; \
540
466k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
466k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
466k
            if (dbg) \
543
466k
                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
466k
        } \
546
1.19M
        break
547
548
1.19M
        const uint16_t *scan;
549
1.19M
        switch (tx_class) {
550
1.11M
        case TX_CLASS_2D: {
551
1.11M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.11M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.11M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.11M
            scan = dav1d_scans[tx];
555
1.11M
            const ptrdiff_t stride = 4 << slh;
556
1.11M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.11M
            const unsigned mask = (4 << slh) - 1;
558
1.11M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.11M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.11M
        }
561
55.4k
        case TX_CLASS_H: {
562
55.4k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
55.4k
            const ptrdiff_t stride = 16;
564
55.4k
            const unsigned shift = slh + 2, shift2 = 0;
565
55.4k
            const unsigned mask = (4 << slh) - 1;
566
55.4k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
55.4k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
55.4k
        }
569
29.8k
        case TX_CLASS_V: {
570
29.8k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
29.8k
            const ptrdiff_t stride = 16;
572
29.8k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
29.8k
            const unsigned mask = (4 << slw) - 1;
574
29.8k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
29.8k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
29.8k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.19M
        }
580
1.24M
    } else { // dc-only
581
1.24M
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
1.24M
        dc_tok = 1 + tok_br;
583
1.24M
        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
1.24M
        if (tok_br == 2) {
587
20.5k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
20.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
20.5k
        }
592
1.24M
        rc = 0;
593
1.24M
    }
594
595
    // residual and sign
596
2.44M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
2.44M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
2.44M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
2.44M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
2.44M
    unsigned cul_level, dc_sign_level;
601
602
2.44M
    if (!dc_tok) {
603
280k
        cul_level = 0;
604
280k
        dc_sign_level = 1 << 6;
605
280k
        if (qm_tbl) goto ac_qm;
606
225k
        goto ac_noqm;
607
280k
    }
608
609
2.16M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
2.16M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
2.16M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
2.16M
    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
2.16M
    int dc_dq = dq_tbl[0];
617
2.16M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
2.16M
    if (qm_tbl) {
620
399k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
399k
        if (dc_tok == 15) {
623
15.2k
            dc_tok = read_golomb(&ts->msac) + 15;
624
15.2k
            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
15.2k
            dc_tok &= 0xfffff;
629
15.2k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
384k
        } else {
631
384k
            dc_dq *= dc_tok;
632
384k
            assert(dc_dq <= 0xffffff);
633
384k
        }
634
399k
        cul_level = dc_tok;
635
399k
        dc_dq >>= dq_shift;
636
399k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
399k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
477k
        if (rc) ac_qm: {
640
477k
            const unsigned ac_dq = dq_tbl[1];
641
4.30M
            do {
642
4.30M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
4.30M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
4.30M
                const unsigned rc_tok = cf[rc];
646
4.30M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
4.30M
                int dq_sat;
648
649
4.30M
                if (rc_tok >= (15 << 11)) {
650
139k
                    tok = read_golomb(&ts->msac) + 15;
651
139k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
139k
                    tok &= 0xfffff;
656
139k
                    dq = (dq * tok) & 0xffffff;
657
4.16M
                } else {
658
4.16M
                    tok = rc_tok >> 11;
659
4.16M
                    dq *= tok;
660
4.16M
                    assert(dq <= 0xffffff);
661
4.16M
                }
662
4.30M
                cul_level += tok;
663
4.30M
                dq >>= dq_shift;
664
4.30M
                dq_sat = umin(dq, cf_max + sign);
665
4.30M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
4.30M
                rc = rc_tok & 0x3ff;
668
4.30M
            } while (rc);
669
477k
        }
670
1.76M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
1.76M
        if (dc_tok == 15) {
673
45.1k
            dc_tok = read_golomb(&ts->msac) + 15;
674
45.1k
            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
45.1k
            dc_tok &= 0xfffff;
679
45.1k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
45.1k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
1.72M
        } else {
682
1.72M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
1.72M
            assert(dc_dq <= cf_max);
684
1.72M
        }
685
1.76M
        cul_level = dc_tok;
686
1.76M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
1.76M
        if (rc) ac_noqm: {
689
1.63M
            const unsigned ac_dq = dq_tbl[1];
690
9.13M
            do {
691
9.13M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
9.13M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
9.13M
                const unsigned rc_tok = cf[rc];
695
9.13M
                unsigned tok;
696
9.13M
                int dq;
697
698
                // residual
699
9.13M
                if (rc_tok >= (15 << 11)) {
700
209k
                    tok = read_golomb(&ts->msac) + 15;
701
209k
                    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
209k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
209k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
209k
                    dq = umin(dq, cf_max + sign);
711
8.92M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
8.92M
                    tok = rc_tok >> 11;
714
8.92M
                    dq = ((ac_dq * tok) >> dq_shift);
715
8.92M
                    assert(dq <= cf_max);
716
8.92M
                }
717
9.13M
                cul_level += tok;
718
9.13M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
9.13M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
9.13M
            } while (rc);
722
1.63M
        }
723
1.76M
    }
724
725
    // context
726
2.44M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
2.44M
    return eob;
729
2.16M
}
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
412k
{
737
412k
    const Dav1dFrameContext *const f = t->f;
738
412k
    Dav1dTileState *const ts = t->ts;
739
412k
    const Dav1dDSPContext *const dsp = f->dsp;
740
412k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
412k
    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
412k
    if (depth < 2 && tx_split[depth] &&
746
57.9k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
44.6k
    {
748
44.6k
        const enum RectTxfmSize sub = t_dim->sub;
749
44.6k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
44.6k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
44.6k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
44.6k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
44.6k
        t->bx += txsw;
755
44.6k
        if (txw >= txh && t->bx < f->bw)
756
33.6k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
33.6k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
44.6k
        t->bx -= txsw;
759
44.6k
        t->by += txsh;
760
44.6k
        if (txh >= txw && t->by < f->bh) {
761
31.5k
            if (dst)
762
6.10k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
31.5k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
31.5k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
31.5k
            t->bx += txsw;
766
31.5k
            if (txw >= txh && t->bx < f->bw)
767
20.6k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
20.6k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
31.5k
            t->bx -= txsw;
770
31.5k
        }
771
44.6k
        t->by -= txsh;
772
367k
    } else {
773
367k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
367k
        enum TxfmType txtp;
775
367k
        uint8_t cf_ctx;
776
367k
        int eob;
777
367k
        coef *cf;
778
779
367k
        if (t->frame_thread.pass) {
780
367k
            const int p = t->frame_thread.pass & 1;
781
367k
            assert(ts->frame_thread[p].cf);
782
367k
            cf = ts->frame_thread[p].cf;
783
367k
            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
784
367k
        } else {
785
0
            cf = bitfn(t->cf);
786
0
        }
787
367k
        if (t->frame_thread.pass != 2) {
788
305k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
305k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
305k
            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
305k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
305k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
305k
#define set_ctx(rep_macro) \
796
1.12M
            for (int y = 0; y < txh; y++) { \
797
814k
                rep_macro(txtp_map, 0, txtp); \
798
814k
                txtp_map += 32; \
799
814k
            }
800
305k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
305k
            case_set_upto16(t_dim->lw);
802
305k
#undef set_ctx
803
305k
            if (t->frame_thread.pass == 1)
804
305k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
305k
        } else {
806
61.9k
            const int cbi = *ts->frame_thread[0].cbi++;
807
61.9k
            eob  = cbi >> 5;
808
61.9k
            txtp = cbi & 0x1f;
809
61.9k
        }
810
367k
        if (!(t->frame_thread.pass & 1)) {
811
61.9k
            assert(dst);
812
61.9k
            if (eob >= 0) {
813
41.9k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
814
0
                    coef_dump(cf, imin(t_dim->h, 8) * 4, imin(t_dim->w, 8) * 4, 3, "dq");
815
41.9k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
41.9k
                                              HIGHBD_CALL_SUFFIX);
817
41.9k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
818
0
                    hex_dump(dst, f->cur.stride[0], t_dim->w * 4, t_dim->h * 4, "recon");
819
41.9k
            }
820
61.9k
        }
821
367k
    }
822
412k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
1.62M
{
827
1.62M
    const Dav1dFrameContext *const f = t->f;
828
1.62M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.62M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.62M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.62M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.62M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.62M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.62M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.62M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.47M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.41M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.62M
    if (b->skip) {
840
891k
        BlockContext *const a = t->a;
841
891k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
891k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
891k
        if (has_chroma) {
844
757k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
757k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
757k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
757k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
757k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
757k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
757k
        }
851
891k
        return;
852
891k
    }
853
854
736k
    Dav1dTileState *const ts = t->ts;
855
736k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
736k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
736k
    assert(t->frame_thread.pass == 1);
858
736k
    assert(!b->skip);
859
736k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
736k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
736k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.50M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
764k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.57M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
813k
            const int sub_w4 = imin(w4, init_x + 16);
867
813k
            int y_off = !!init_y, y, x;
868
1.81M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.00M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.00M
            {
871
1.00M
                int x_off = !!init_x;
872
3.26M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.26M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.26M
                {
875
2.26M
                    if (!b->intra) {
876
234k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
234k
                                       x_off, y_off, NULL);
878
2.03M
                    } else {
879
2.03M
                        uint8_t cf_ctx = 0x40;
880
2.03M
                        enum TxfmType txtp;
881
2.03M
                        const int eob =
882
2.03M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
2.03M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
2.03M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
2.03M
                        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
2.03M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
2.03M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
2.03M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
2.03M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
2.03M
                    }
893
2.26M
                }
894
1.00M
                t->bx -= x;
895
1.00M
            }
896
813k
            t->by -= y;
897
898
813k
            if (!has_chroma) continue;
899
900
664k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
664k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.99M
            for (int pl = 0; pl < 2; pl++) {
903
2.84M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.51M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.51M
                {
906
3.56M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.05M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.05M
                    {
909
2.05M
                        uint8_t cf_ctx = 0x40;
910
2.05M
                        enum TxfmType txtp;
911
2.05M
                        if (!b->intra)
912
288k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
288k
                                                        bx4 + (x << ss_hor)];
914
2.05M
                        const int eob =
915
2.05M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.05M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.05M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.05M
                                         &txtp, &cf_ctx);
919
2.05M
                        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
2.05M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.05M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.05M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.05M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.05M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.05M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.05M
                    }
930
1.51M
                    t->bx -= x << ss_hor;
931
1.51M
                }
932
1.32M
                t->by -= y << ss_ver;
933
1.32M
            }
934
664k
        }
935
764k
    }
936
736k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
791k
{
827
791k
    const Dav1dFrameContext *const f = t->f;
828
791k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
791k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
791k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
791k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
791k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
791k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
791k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
791k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
717k
                           (bw4 > ss_hor || t->bx & 1) &&
837
687k
                           (bh4 > ss_ver || t->by & 1);
838
839
791k
    if (b->skip) {
840
444k
        BlockContext *const a = t->a;
841
444k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
444k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
444k
        if (has_chroma) {
844
378k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
378k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
378k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
378k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
378k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
378k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
378k
        }
851
444k
        return;
852
444k
    }
853
854
347k
    Dav1dTileState *const ts = t->ts;
855
347k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
347k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
347k
    assert(t->frame_thread.pass == 1);
858
347k
    assert(!b->skip);
859
347k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
347k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
347k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
704k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
357k
        const int sub_h4 = imin(h4, 16 + init_y);
865
733k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
375k
            const int sub_w4 = imin(w4, init_x + 16);
867
375k
            int y_off = !!init_y, y, x;
868
839k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
463k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
463k
            {
871
463k
                int x_off = !!init_x;
872
1.59M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.13M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.13M
                {
875
1.13M
                    if (!b->intra) {
876
144k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
144k
                                       x_off, y_off, NULL);
878
988k
                    } else {
879
988k
                        uint8_t cf_ctx = 0x40;
880
988k
                        enum TxfmType txtp;
881
988k
                        const int eob =
882
988k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
988k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
988k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
988k
                        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
988k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
988k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
988k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
988k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
988k
                    }
893
1.13M
                }
894
463k
                t->bx -= x;
895
463k
            }
896
375k
            t->by -= y;
897
898
375k
            if (!has_chroma) continue;
899
900
304k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
304k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
913k
            for (int pl = 0; pl < 2; pl++) {
903
1.28M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
678k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
678k
                {
906
1.56M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
887k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
887k
                    {
909
887k
                        uint8_t cf_ctx = 0x40;
910
887k
                        enum TxfmType txtp;
911
887k
                        if (!b->intra)
912
144k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
144k
                                                        bx4 + (x << ss_hor)];
914
887k
                        const int eob =
915
887k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
887k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
887k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
887k
                                         &txtp, &cf_ctx);
919
887k
                        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
887k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
887k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
887k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
887k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
887k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
887k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
887k
                    }
930
678k
                    t->bx -= x << ss_hor;
931
678k
                }
932
608k
                t->by -= y << ss_ver;
933
608k
            }
934
304k
        }
935
357k
    }
936
347k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
837k
{
827
837k
    const Dav1dFrameContext *const f = t->f;
828
837k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
837k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
837k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
837k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
837k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
837k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
837k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
837k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
752k
                           (bw4 > ss_hor || t->bx & 1) &&
837
727k
                           (bh4 > ss_ver || t->by & 1);
838
839
837k
    if (b->skip) {
840
447k
        BlockContext *const a = t->a;
841
447k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
447k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
447k
        if (has_chroma) {
844
379k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
379k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
379k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
379k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
379k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
379k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
379k
        }
851
447k
        return;
852
447k
    }
853
854
389k
    Dav1dTileState *const ts = t->ts;
855
389k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
389k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
389k
    assert(t->frame_thread.pass == 1);
858
389k
    assert(!b->skip);
859
389k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
389k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
389k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
796k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
406k
        const int sub_h4 = imin(h4, 16 + init_y);
865
843k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
437k
            const int sub_w4 = imin(w4, init_x + 16);
867
437k
            int y_off = !!init_y, y, x;
868
974k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
537k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
537k
            {
871
537k
                int x_off = !!init_x;
872
1.67M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.13M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.13M
                {
875
1.13M
                    if (!b->intra) {
876
90.3k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
90.3k
                                       x_off, y_off, NULL);
878
1.04M
                    } else {
879
1.04M
                        uint8_t cf_ctx = 0x40;
880
1.04M
                        enum TxfmType txtp;
881
1.04M
                        const int eob =
882
1.04M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.04M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.04M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.04M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
1.04M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.04M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.04M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.04M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.04M
                    }
893
1.13M
                }
894
537k
                t->bx -= x;
895
537k
            }
896
437k
            t->by -= y;
897
898
437k
            if (!has_chroma) continue;
899
900
359k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
359k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.07M
            for (int pl = 0; pl < 2; pl++) {
903
1.55M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
834k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
834k
                {
906
1.99M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.16M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.16M
                    {
909
1.16M
                        uint8_t cf_ctx = 0x40;
910
1.16M
                        enum TxfmType txtp;
911
1.16M
                        if (!b->intra)
912
143k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
143k
                                                        bx4 + (x << ss_hor)];
914
1.16M
                        const int eob =
915
1.16M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.16M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.16M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.16M
                                         &txtp, &cf_ctx);
919
1.16M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.16M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.16M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.16M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.16M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.16M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.16M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.16M
                    }
930
834k
                    t->bx -= x << ss_hor;
931
834k
                }
932
718k
                t->by -= y << ss_ver;
933
718k
            }
934
359k
        }
935
406k
    }
936
389k
}
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
326k
{
945
326k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
326k
    const Dav1dFrameContext *const f = t->f;
947
326k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
326k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
326k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
326k
    const int mvx = mv.x, mvy = mv.y;
951
326k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
326k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
326k
    const pixel *ref;
954
955
326k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
127k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
127k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
127k
        int w, h;
959
960
127k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
105k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
105k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
105k
        } else {
964
21.9k
            w = f->bw * 4 >> ss_hor;
965
21.9k
            h = f->bh * 4 >> ss_ver;
966
21.9k
        }
967
127k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
88.3k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
53.5k
            dy + bh4 * v_mul + !!my * 4 > h)
970
82.1k
        {
971
82.1k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
82.1k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
82.1k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
82.1k
                                emu_edge_buf, 192 * sizeof(pixel),
975
82.1k
                                refp->p.data[pl], ref_stride);
976
82.1k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
82.1k
            ref_stride = 192 * sizeof(pixel);
978
82.1k
        } else {
979
44.9k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
44.9k
        }
981
982
127k
        if (dst8 != NULL) {
983
102k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
102k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
102k
                                     HIGHBD_CALL_SUFFIX);
986
102k
        } else {
987
24.8k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
24.8k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
24.8k
                                      HIGHBD_CALL_SUFFIX);
990
24.8k
        }
991
199k
    } else {
992
199k
        assert(refp != &f->sr_cur);
993
994
199k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
199k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
398k
#define scale_mv(res, val, scale) do { \
997
398k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
398k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
398k
        } while (0)
1000
199k
        int pos_y, pos_x;
1001
199k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
199k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
199k
#undef scale_mv
1004
199k
        const int left = pos_x >> 10;
1005
199k
        const int top = pos_y >> 10;
1006
199k
        const int right =
1007
199k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
199k
        const int bottom =
1009
199k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
199k
        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
199k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
199k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
199k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
188k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
188k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
188k
                                w, h, left - 3, top - 3,
1023
188k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
188k
                                refp->p.data[pl], ref_stride);
1025
188k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
188k
            ref_stride = 320 * sizeof(pixel);
1027
188k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
188k
        } else {
1029
11.1k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
11.1k
        }
1031
1032
199k
        if (dst8 != NULL) {
1033
144k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
144k
                                            bw4 * h_mul, bh4 * v_mul,
1035
144k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
144k
                                            f->svc[refidx][0].step,
1037
144k
                                            f->svc[refidx][1].step
1038
144k
                                            HIGHBD_CALL_SUFFIX);
1039
144k
        } else {
1040
55.1k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
55.1k
                                             bw4 * h_mul, bh4 * v_mul,
1042
55.1k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
55.1k
                                             f->svc[refidx][0].step,
1044
55.1k
                                             f->svc[refidx][1].step
1045
55.1k
                                             HIGHBD_CALL_SUFFIX);
1046
55.1k
        }
1047
199k
    }
1048
1049
326k
    return 0;
1050
326k
}
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
31.7k
{
1057
31.7k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
31.7k
    const Dav1dFrameContext *const f = t->f;
1059
31.7k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
31.7k
    pixel *const lap = bitfn(t->scratch.lap);
1061
31.7k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
31.7k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
31.7k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
31.7k
    int res;
1065
1066
31.7k
    if (t->by > t->ts->tiling.row_start &&
1067
27.9k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
18.7k
    {
1069
40.0k
        for (int i = 0, x = 0; x < w4 && i < imin(b_dim[2], 4); ) {
1070
            // only odd blocks are considered for overlap handling, hence +1
1071
21.2k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
21.2k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
21.2k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
21.2k
            if (a_r->ref.ref[0] > 0) {
1076
20.9k
                const int ow4 = imin(step4, b_dim[0]);
1077
20.9k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
20.9k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
20.9k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
20.9k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
20.9k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
20.9k
                if (res) return res;
1083
20.9k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
20.9k
                                   h_mul * ow4, v_mul * oh4);
1085
20.9k
                i++;
1086
20.9k
            }
1087
21.2k
            x += step4;
1088
21.2k
        }
1089
18.7k
    }
1090
1091
31.7k
    if (t->bx > t->ts->tiling.col_start)
1092
44.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
23.4k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
23.4k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
23.4k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
23.4k
            if (l_r->ref.ref[0] > 0) {
1099
23.0k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
23.0k
                const int oh4 = imin(step4, b_dim[1]);
1101
23.0k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
23.0k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
23.0k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
23.0k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
23.0k
                if (res) return res;
1106
23.0k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
23.0k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
23.0k
                i++;
1109
23.0k
            }
1110
23.4k
            y += step4;
1111
23.4k
        }
1112
31.7k
    return 0;
1113
31.7k
}
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
12.5k
{
1121
12.5k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
12.5k
    const Dav1dFrameContext *const f = t->f;
1123
12.5k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
12.5k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
12.5k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
12.5k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
12.5k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
12.5k
    const int32_t *const mat = wmp->matrix;
1129
12.5k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
12.5k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
42.0k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
29.4k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
29.4k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
29.4k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
102k
        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
72.9k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
72.9k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
72.9k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
72.9k
            const int dx = (int) (mvx >> 16) - 4;
1144
72.9k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
72.9k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
72.9k
            const int dy = (int) (mvy >> 16) - 4;
1147
72.9k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
72.9k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
72.9k
            const pixel *ref_ptr;
1151
72.9k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
72.9k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
41.1k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
41.1k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
41.1k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
41.1k
                                    refp->p.data[pl], ref_stride);
1158
41.1k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
41.1k
                ref_stride = 32 * sizeof(pixel);
1160
41.1k
            } else {
1161
31.8k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
31.8k
            }
1163
72.9k
            if (dst16 != NULL)
1164
9.33k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
9.33k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
63.6k
            else
1167
63.6k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
63.6k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
72.9k
        }
1170
29.4k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
2.73k
        else      dst16 += 8 * dstride;
1172
29.4k
    }
1173
12.5k
    return 0;
1174
12.5k
}
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
281k
{
1180
281k
    Dav1dTileState *const ts = t->ts;
1181
281k
    const Dav1dFrameContext *const f = t->f;
1182
281k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
281k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
281k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
281k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
281k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
281k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
281k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
281k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
281k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
281k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
199k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
194k
                           (bh4 > ss_ver || t->by & 1);
1194
281k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
281k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
281k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
281k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
281k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
600k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
318k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
318k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
694k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
375k
            if (b->pal_sz[0]) {
1208
568
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
568
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
568
                const uint8_t *pal_idx;
1211
568
                if (t->frame_thread.pass) {
1212
568
                    const int p = t->frame_thread.pass & 1;
1213
568
                    assert(ts->frame_thread[p].pal_idx);
1214
568
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
568
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
568
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
568
                const pixel *const pal = t->frame_thread.pass ?
1220
568
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
568
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
568
                    bytefn(t->scratch.pal)[0];
1223
568
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
568
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
568
                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
568
            }
1229
1230
375k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
375k
                                     sm_flag(&t->l, by4) |
1232
375k
                                     intra_edge_filter_flag);
1233
375k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
318k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
375k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
318k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
375k
            int y, x;
1238
375k
            const int sub_w4 = imin(w4, init_x + 16);
1239
986k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
611k
                 y += t_dim->h, t->by += t_dim->h)
1241
611k
            {
1242
611k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
611k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
611k
                                    t->bx + init_x);
1245
3.38M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.77M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.77M
                {
1248
2.77M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.76M
                    int angle = b->y_angle;
1251
2.76M
                    const enum EdgeFlags edge_flags =
1252
2.76M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
2.46M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.76M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
2.38M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.76M
                    const pixel *top_sb_edge = NULL;
1257
2.76M
                    if (!(t->by & (f->sb_step - 1))) {
1258
326k
                        top_sb_edge = f->ipred_edge[0];
1259
326k
                        const int sby = t->by >> f->sb_shift;
1260
326k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
326k
                    }
1262
2.76M
                    const enum IntraPredMode m =
1263
2.76M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.76M
                                                          t->bx > ts->tiling.col_start,
1265
2.76M
                                                          t->by,
1266
2.76M
                                                          t->by > ts->tiling.row_start,
1267
2.76M
                                                          ts->tiling.col_end,
1268
2.76M
                                                          ts->tiling.row_end,
1269
2.76M
                                                          edge_flags, dst,
1270
2.76M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.76M
                                                          b->y_mode, &angle,
1272
2.76M
                                                          t_dim->w, t_dim->h,
1273
2.76M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.76M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.76M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.76M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.76M
                                             angle | intra_flags,
1278
2.76M
                                             4 * f->bw - 4 * t->bx,
1279
2.76M
                                             4 * f->bh - 4 * t->by
1280
2.76M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.76M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
2.77M
                skip_y_pred: {}
1293
2.77M
                    if (!b->skip) {
1294
884k
                        coef *cf;
1295
884k
                        int eob;
1296
884k
                        enum TxfmType txtp;
1297
884k
                        if (t->frame_thread.pass) {
1298
884k
                            const int p = t->frame_thread.pass & 1;
1299
884k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
884k
                            cf = ts->frame_thread[p].cf;
1301
884k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
884k
                            eob  = cbi >> 5;
1303
884k
                            txtp = cbi & 0x1f;
1304
884k
                        } else {
1305
1
                            uint8_t cf_ctx;
1306
1
                            cf = bitfn(t->cf);
1307
1
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
1
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
1
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
1
                            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
1
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
1
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
1
                        }
1316
884k
                        if (eob >= 0) {
1317
767k
                            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
767k
                            dsp->itx.itxfm_add[b->tx]
1321
767k
                                              [txtp](dst,
1322
767k
                                                     f->cur.stride[0],
1323
767k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
767k
                            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
767k
                        }
1328
1.88M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
2.77M
                    dst += 4 * t_dim->w;
1333
2.77M
                }
1334
611k
                t->bx -= x;
1335
611k
            }
1336
375k
            t->by -= y;
1337
1338
375k
            if (!has_chroma) continue;
1339
1340
238k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
238k
            if (b->uv_mode == CFL_PRED) {
1343
33.5k
                assert(!init_x && !init_y);
1344
1345
33.5k
                int16_t *const ac = t->scratch.ac;
1346
33.5k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
33.5k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
33.5k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
33.5k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
33.5k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
33.5k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
33.5k
                const int furthest_r =
1354
33.5k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
33.5k
                const int furthest_b =
1356
33.5k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
33.5k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
33.5k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
33.5k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
33.5k
                                                         cbw4 * 4, cbh4 * 4);
1361
100k
                for (int pl = 0; pl < 2; pl++) {
1362
67.1k
                    if (!b->cfl_alpha[pl]) continue;
1363
57.1k
                    int angle = 0;
1364
57.1k
                    const pixel *top_sb_edge = NULL;
1365
57.1k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
25.4k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
25.4k
                        const int sby = t->by >> f->sb_shift;
1368
25.4k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
25.4k
                    }
1370
57.1k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
57.1k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
57.1k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
57.1k
                    const enum IntraPredMode m =
1374
57.1k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
57.1k
                                                          ypos, ypos > ystart,
1376
57.1k
                                                          ts->tiling.col_end >> ss_hor,
1377
57.1k
                                                          ts->tiling.row_end >> ss_ver,
1378
57.1k
                                                          0, uv_dst[pl], stride,
1379
57.1k
                                                          top_sb_edge, DC_PRED, &angle,
1380
57.1k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
57.1k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
57.1k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
57.1k
                                           uv_t_dim->w * 4,
1384
57.1k
                                           uv_t_dim->h * 4,
1385
57.1k
                                           ac, b->cfl_alpha[pl]
1386
57.1k
                                           HIGHBD_CALL_SUFFIX);
1387
57.1k
                }
1388
33.5k
                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
205k
            } else if (b->pal_sz[1]) {
1394
201
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
201
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
201
                const pixel (*pal)[8];
1397
201
                const uint8_t *pal_idx;
1398
201
                if (t->frame_thread.pass) {
1399
201
                    const int p = t->frame_thread.pass & 1;
1400
201
                    assert(ts->frame_thread[p].pal_idx);
1401
201
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
201
                                              ((t->bx >> 1) + (t->by & 1))];
1403
201
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
201
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
201
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
201
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
201
                                       f->cur.stride[1], pal[1],
1412
201
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
201
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
201
                                       f->cur.stride[1], pal[2],
1415
201
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
201
                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
201
            }
1425
1426
238k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
238k
                                 sm_uv_flag(&t->l, cby4);
1428
238k
            const int uv_sb_has_tr =
1429
238k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
211k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
238k
            const int uv_sb_has_bl =
1432
238k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
211k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
238k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
715k
            for (int pl = 0; pl < 2; pl++) {
1436
1.14M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
671k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
671k
                {
1439
671k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
671k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
671k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.86M
                    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.13M
                            b->pal_sz[1])
1447
57.8k
                        {
1448
57.8k
                            goto skip_uv_pred;
1449
57.8k
                        }
1450
1451
1.13M
                        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.13M
                        const enum EdgeFlags edge_flags =
1456
1.13M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
664k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
859k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.13M
                            ((x > (init_x >> ss_hor) ||
1460
614k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
755k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.13M
                        const pixel *top_sb_edge = NULL;
1463
1.13M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
343k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
343k
                            const int sby = t->by >> f->sb_shift;
1466
343k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
343k
                        }
1468
1.13M
                        const enum IntraPredMode uv_mode =
1469
1.13M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.13M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.13M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.13M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.13M
                        const enum IntraPredMode m =
1474
1.13M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.13M
                                                              ypos, ypos > ystart,
1476
1.13M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.13M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.13M
                                                              edge_flags, dst, stride,
1479
1.13M
                                                              top_sb_edge, uv_mode,
1480
1.13M
                                                              &angle, uv_t_dim->w,
1481
1.13M
                                                              uv_t_dim->h,
1482
1.13M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.13M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.13M
                        angle |= intra_edge_filter_flag;
1485
1.13M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.13M
                                                 uv_t_dim->w * 4,
1487
1.13M
                                                 uv_t_dim->h * 4,
1488
1.13M
                                                 angle | sm_uv_fl,
1489
1.13M
                                                 (4 * f->bw + ss_hor -
1490
1.13M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.13M
                                                 (4 * f->bh + ss_ver -
1492
1.13M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.13M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.13M
                        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
344k
                            enum TxfmType txtp;
1507
344k
                            int eob;
1508
344k
                            coef *cf;
1509
344k
                            if (t->frame_thread.pass) {
1510
344k
                                const int p = t->frame_thread.pass & 1;
1511
344k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
344k
                                cf = ts->frame_thread[p].cf;
1513
344k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
344k
                                eob  = cbi >> 5;
1515
344k
                                txtp = cbi & 0x1f;
1516
344k
                            } 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
344k
                            if (eob >= 0) {
1533
109k
                                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
109k
                                dsp->itx.itxfm_add[b->uvtx]
1537
109k
                                                  [txtp](dst, stride,
1538
109k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
109k
                                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
109k
                            }
1543
843k
                        } 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
671k
                    t->bx -= x << ss_hor;
1550
671k
                }
1551
476k
                t->by -= y << ss_ver;
1552
476k
            }
1553
238k
        }
1554
318k
    }
1555
281k
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
126k
{
1180
126k
    Dav1dTileState *const ts = t->ts;
1181
126k
    const Dav1dFrameContext *const f = t->f;
1182
126k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
126k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
126k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
126k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
126k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
126k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
126k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
126k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
126k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
126k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
91.7k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
89.3k
                           (bh4 > ss_ver || t->by & 1);
1194
126k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
126k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
126k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
126k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
126k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
266k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
139k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
139k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
299k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
160k
            if (b->pal_sz[0]) {
1208
206
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
206
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
206
                const uint8_t *pal_idx;
1211
206
                if (t->frame_thread.pass) {
1212
206
                    const int p = t->frame_thread.pass & 1;
1213
206
                    assert(ts->frame_thread[p].pal_idx);
1214
206
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
206
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
206
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
206
                const pixel *const pal = t->frame_thread.pass ?
1220
206
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
206
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
206
                    bytefn(t->scratch.pal)[0];
1223
206
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
206
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
206
                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
206
            }
1229
1230
160k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
160k
                                     sm_flag(&t->l, by4) |
1232
160k
                                     intra_edge_filter_flag);
1233
160k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
139k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
160k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
139k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
160k
            int y, x;
1238
160k
            const int sub_w4 = imin(w4, init_x + 16);
1239
395k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
235k
                 y += t_dim->h, t->by += t_dim->h)
1241
235k
            {
1242
235k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
235k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
235k
                                    t->bx + init_x);
1245
968k
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
733k
                     x += t_dim->w, t->bx += t_dim->w)
1247
733k
                {
1248
733k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
732k
                    int angle = b->y_angle;
1251
732k
                    const enum EdgeFlags edge_flags =
1252
732k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
630k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
732k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
596k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
732k
                    const pixel *top_sb_edge = NULL;
1257
732k
                    if (!(t->by & (f->sb_step - 1))) {
1258
130k
                        top_sb_edge = f->ipred_edge[0];
1259
130k
                        const int sby = t->by >> f->sb_shift;
1260
130k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
130k
                    }
1262
732k
                    const enum IntraPredMode m =
1263
732k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
732k
                                                          t->bx > ts->tiling.col_start,
1265
732k
                                                          t->by,
1266
732k
                                                          t->by > ts->tiling.row_start,
1267
732k
                                                          ts->tiling.col_end,
1268
732k
                                                          ts->tiling.row_end,
1269
732k
                                                          edge_flags, dst,
1270
732k
                                                          f->cur.stride[0], top_sb_edge,
1271
732k
                                                          b->y_mode, &angle,
1272
732k
                                                          t_dim->w, t_dim->h,
1273
732k
                                                          f->seq_hdr->intra_edge_filter,
1274
732k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
732k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
732k
                                             t_dim->w * 4, t_dim->h * 4,
1277
732k
                                             angle | intra_flags,
1278
732k
                                             4 * f->bw - 4 * t->bx,
1279
732k
                                             4 * f->bh - 4 * t->by
1280
732k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
732k
                    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
733k
                skip_y_pred: {}
1293
733k
                    if (!b->skip) {
1294
480k
                        coef *cf;
1295
480k
                        int eob;
1296
480k
                        enum TxfmType txtp;
1297
480k
                        if (t->frame_thread.pass) {
1298
480k
                            const int p = t->frame_thread.pass & 1;
1299
480k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
480k
                            cf = ts->frame_thread[p].cf;
1301
480k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
480k
                            eob  = cbi >> 5;
1303
480k
                            txtp = cbi & 0x1f;
1304
480k
                        } 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
480k
                        if (eob >= 0) {
1317
427k
                            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
427k
                            dsp->itx.itxfm_add[b->tx]
1321
427k
                                              [txtp](dst,
1322
427k
                                                     f->cur.stride[0],
1323
427k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
427k
                            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
427k
                        }
1328
480k
                    } 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
733k
                    dst += 4 * t_dim->w;
1333
733k
                }
1334
235k
                t->bx -= x;
1335
235k
            }
1336
160k
            t->by -= y;
1337
1338
160k
            if (!has_chroma) continue;
1339
1340
110k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
110k
            if (b->uv_mode == CFL_PRED) {
1343
15.0k
                assert(!init_x && !init_y);
1344
1345
15.0k
                int16_t *const ac = t->scratch.ac;
1346
15.0k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
15.0k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
15.0k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
15.0k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
15.0k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
15.0k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
15.0k
                const int furthest_r =
1354
15.0k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
15.0k
                const int furthest_b =
1356
15.0k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
15.0k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
15.0k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
15.0k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
15.0k
                                                         cbw4 * 4, cbh4 * 4);
1361
45.2k
                for (int pl = 0; pl < 2; pl++) {
1362
30.1k
                    if (!b->cfl_alpha[pl]) continue;
1363
25.4k
                    int angle = 0;
1364
25.4k
                    const pixel *top_sb_edge = NULL;
1365
25.4k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
11.3k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
11.3k
                        const int sby = t->by >> f->sb_shift;
1368
11.3k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
11.3k
                    }
1370
25.4k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
25.4k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
25.4k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
25.4k
                    const enum IntraPredMode m =
1374
25.4k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
25.4k
                                                          ypos, ypos > ystart,
1376
25.4k
                                                          ts->tiling.col_end >> ss_hor,
1377
25.4k
                                                          ts->tiling.row_end >> ss_ver,
1378
25.4k
                                                          0, uv_dst[pl], stride,
1379
25.4k
                                                          top_sb_edge, DC_PRED, &angle,
1380
25.4k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
25.4k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
25.4k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
25.4k
                                           uv_t_dim->w * 4,
1384
25.4k
                                           uv_t_dim->h * 4,
1385
25.4k
                                           ac, b->cfl_alpha[pl]
1386
25.4k
                                           HIGHBD_CALL_SUFFIX);
1387
25.4k
                }
1388
15.0k
                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
95.4k
            } else if (b->pal_sz[1]) {
1394
66
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
66
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
66
                const pixel (*pal)[8];
1397
66
                const uint8_t *pal_idx;
1398
66
                if (t->frame_thread.pass) {
1399
66
                    const int p = t->frame_thread.pass & 1;
1400
66
                    assert(ts->frame_thread[p].pal_idx);
1401
66
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
66
                                              ((t->bx >> 1) + (t->by & 1))];
1403
66
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
66
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
66
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
66
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
66
                                       f->cur.stride[1], pal[1],
1412
66
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
66
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
66
                                       f->cur.stride[1], pal[2],
1415
66
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
66
                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
66
            }
1425
1426
110k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
110k
                                 sm_uv_flag(&t->l, cby4);
1428
110k
            const int uv_sb_has_tr =
1429
110k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
97.3k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
110k
            const int uv_sb_has_bl =
1432
110k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
97.3k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
110k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
331k
            for (int pl = 0; pl < 2; pl++) {
1436
542k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
321k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
321k
                {
1439
321k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
321k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
321k
                                        ((t->bx + init_x) >> ss_hor));
1442
906k
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
584k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
584k
                    {
1445
584k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
559k
                            b->pal_sz[1])
1447
25.6k
                        {
1448
25.6k
                            goto skip_uv_pred;
1449
25.6k
                        }
1450
1451
559k
                        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
559k
                        const enum EdgeFlags edge_flags =
1456
559k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
334k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
422k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
559k
                            ((x > (init_x >> ss_hor) ||
1460
296k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
375k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
559k
                        const pixel *top_sb_edge = NULL;
1463
559k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
167k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
167k
                            const int sby = t->by >> f->sb_shift;
1466
167k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
167k
                        }
1468
559k
                        const enum IntraPredMode uv_mode =
1469
559k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
559k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
559k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
559k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
559k
                        const enum IntraPredMode m =
1474
559k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
559k
                                                              ypos, ypos > ystart,
1476
559k
                                                              ts->tiling.col_end >> ss_hor,
1477
559k
                                                              ts->tiling.row_end >> ss_ver,
1478
559k
                                                              edge_flags, dst, stride,
1479
559k
                                                              top_sb_edge, uv_mode,
1480
559k
                                                              &angle, uv_t_dim->w,
1481
559k
                                                              uv_t_dim->h,
1482
559k
                                                              f->seq_hdr->intra_edge_filter,
1483
559k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
559k
                        angle |= intra_edge_filter_flag;
1485
559k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
559k
                                                 uv_t_dim->w * 4,
1487
559k
                                                 uv_t_dim->h * 4,
1488
559k
                                                 angle | sm_uv_fl,
1489
559k
                                                 (4 * f->bw + ss_hor -
1490
559k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
559k
                                                 (4 * f->bh + ss_ver -
1492
559k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
559k
                                                 HIGHBD_CALL_SUFFIX);
1494
559k
                        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
584k
                    skip_uv_pred: {}
1505
584k
                        if (!b->skip) {
1506
173k
                            enum TxfmType txtp;
1507
173k
                            int eob;
1508
173k
                            coef *cf;
1509
173k
                            if (t->frame_thread.pass) {
1510
173k
                                const int p = t->frame_thread.pass & 1;
1511
173k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
173k
                                cf = ts->frame_thread[p].cf;
1513
173k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
173k
                                eob  = cbi >> 5;
1515
173k
                                txtp = cbi & 0x1f;
1516
173k
                            } 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
173k
                            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
410k
                        } 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
584k
                        dst += uv_t_dim->w * 4;
1548
584k
                    }
1549
321k
                    t->bx -= x << ss_hor;
1550
321k
                }
1551
220k
                t->by -= y << ss_ver;
1552
220k
            }
1553
110k
        }
1554
139k
    }
1555
126k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
155k
{
1180
155k
    Dav1dTileState *const ts = t->ts;
1181
155k
    const Dav1dFrameContext *const f = t->f;
1182
155k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
155k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
155k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
155k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
155k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
155k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
155k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
155k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
155k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
155k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
107k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
105k
                           (bh4 > ss_ver || t->by & 1);
1194
155k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
155k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
155k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
155k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
155k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
334k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
179k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
179k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
394k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
215k
            if (b->pal_sz[0]) {
1208
362
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
362
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
362
                const uint8_t *pal_idx;
1211
362
                if (t->frame_thread.pass) {
1212
362
                    const int p = t->frame_thread.pass & 1;
1213
362
                    assert(ts->frame_thread[p].pal_idx);
1214
362
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
362
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
362
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
362
                const pixel *const pal = t->frame_thread.pass ?
1220
362
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
362
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
362
                    bytefn(t->scratch.pal)[0];
1223
362
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
362
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
362
                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
362
            }
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
179k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
215k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
179k
                              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
591k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
376k
                 y += t_dim->h, t->by += t_dim->h)
1241
375k
            {
1242
375k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
375k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
375k
                                    t->bx + init_x);
1245
2.41M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.03M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.03M
                {
1248
2.03M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.03M
                    int angle = b->y_angle;
1251
2.03M
                    const enum EdgeFlags edge_flags =
1252
2.03M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.83M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.03M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.78M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.03M
                    const pixel *top_sb_edge = NULL;
1257
2.03M
                    if (!(t->by & (f->sb_step - 1))) {
1258
196k
                        top_sb_edge = f->ipred_edge[0];
1259
196k
                        const int sby = t->by >> f->sb_shift;
1260
196k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
196k
                    }
1262
2.03M
                    const enum IntraPredMode m =
1263
2.03M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.03M
                                                          t->bx > ts->tiling.col_start,
1265
2.03M
                                                          t->by,
1266
2.03M
                                                          t->by > ts->tiling.row_start,
1267
2.03M
                                                          ts->tiling.col_end,
1268
2.03M
                                                          ts->tiling.row_end,
1269
2.03M
                                                          edge_flags, dst,
1270
2.03M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.03M
                                                          b->y_mode, &angle,
1272
2.03M
                                                          t_dim->w, t_dim->h,
1273
2.03M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.03M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.03M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.03M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.03M
                                             angle | intra_flags,
1278
2.03M
                                             4 * f->bw - 4 * t->bx,
1279
2.03M
                                             4 * f->bh - 4 * t->by
1280
2.03M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.03M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
2.03M
                skip_y_pred: {}
1293
2.03M
                    if (!b->skip) {
1294
403k
                        coef *cf;
1295
403k
                        int eob;
1296
403k
                        enum TxfmType txtp;
1297
403k
                        if (t->frame_thread.pass) {
1298
403k
                            const int p = t->frame_thread.pass & 1;
1299
403k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
403k
                            cf = ts->frame_thread[p].cf;
1301
403k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
403k
                            eob  = cbi >> 5;
1303
403k
                            txtp = cbi & 0x1f;
1304
403k
                        } else {
1305
1
                            uint8_t cf_ctx;
1306
1
                            cf = bitfn(t->cf);
1307
1
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
1
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
1
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
1
                            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
1
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
1
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
1
                        }
1316
403k
                        if (eob >= 0) {
1317
340k
                            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
340k
                            dsp->itx.itxfm_add[b->tx]
1321
340k
                                              [txtp](dst,
1322
340k
                                                     f->cur.stride[0],
1323
340k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
340k
                            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
340k
                        }
1328
1.63M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
2.03M
                    dst += 4 * t_dim->w;
1333
2.03M
                }
1334
376k
                t->bx -= x;
1335
376k
            }
1336
215k
            t->by -= y;
1337
1338
215k
            if (!has_chroma) continue;
1339
1340
128k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
128k
            if (b->uv_mode == CFL_PRED) {
1343
18.5k
                assert(!init_x && !init_y);
1344
1345
18.5k
                int16_t *const ac = t->scratch.ac;
1346
18.5k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
18.5k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
18.5k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
18.5k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
18.5k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
18.5k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
18.5k
                const int furthest_r =
1354
18.5k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
18.5k
                const int furthest_b =
1356
18.5k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
18.5k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
18.5k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
18.5k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
18.5k
                                                         cbw4 * 4, cbh4 * 4);
1361
55.5k
                for (int pl = 0; pl < 2; pl++) {
1362
37.0k
                    if (!b->cfl_alpha[pl]) continue;
1363
31.6k
                    int angle = 0;
1364
31.6k
                    const pixel *top_sb_edge = NULL;
1365
31.6k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
14.0k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
14.0k
                        const int sby = t->by >> f->sb_shift;
1368
14.0k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
14.0k
                    }
1370
31.6k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
31.6k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
31.6k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
31.6k
                    const enum IntraPredMode m =
1374
31.6k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
31.6k
                                                          ypos, ypos > ystart,
1376
31.6k
                                                          ts->tiling.col_end >> ss_hor,
1377
31.6k
                                                          ts->tiling.row_end >> ss_ver,
1378
31.6k
                                                          0, uv_dst[pl], stride,
1379
31.6k
                                                          top_sb_edge, DC_PRED, &angle,
1380
31.6k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
31.6k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
31.6k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
31.6k
                                           uv_t_dim->w * 4,
1384
31.6k
                                           uv_t_dim->h * 4,
1385
31.6k
                                           ac, b->cfl_alpha[pl]
1386
31.6k
                                           HIGHBD_CALL_SUFFIX);
1387
31.6k
                }
1388
18.5k
                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
109k
            } else if (b->pal_sz[1]) {
1394
135
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
135
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
135
                const pixel (*pal)[8];
1397
135
                const uint8_t *pal_idx;
1398
135
                if (t->frame_thread.pass) {
1399
135
                    const int p = t->frame_thread.pass & 1;
1400
135
                    assert(ts->frame_thread[p].pal_idx);
1401
135
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
135
                                              ((t->bx >> 1) + (t->by & 1))];
1403
135
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
135
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
135
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
135
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
135
                                       f->cur.stride[1], pal[1],
1412
135
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
135
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
135
                                       f->cur.stride[1], pal[2],
1415
135
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
135
                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
135
            }
1425
1426
128k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
128k
                                 sm_uv_flag(&t->l, cby4);
1428
128k
            const int uv_sb_has_tr =
1429
128k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
114k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
128k
            const int uv_sb_has_bl =
1432
128k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
114k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
128k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
383k
            for (int pl = 0; pl < 2; pl++) {
1436
605k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
349k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
349k
                {
1439
349k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
349k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
349k
                                        ((t->bx + init_x) >> ss_hor));
1442
953k
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
603k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
603k
                    {
1445
603k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
571k
                            b->pal_sz[1])
1447
32.2k
                        {
1448
32.2k
                            goto skip_uv_pred;
1449
32.2k
                        }
1450
1451
571k
                        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
571k
                        const enum EdgeFlags edge_flags =
1456
571k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
330k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
437k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
571k
                            ((x > (init_x >> ss_hor) ||
1460
317k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
380k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
571k
                        const pixel *top_sb_edge = NULL;
1463
571k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
175k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
175k
                            const int sby = t->by >> f->sb_shift;
1466
175k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
175k
                        }
1468
571k
                        const enum IntraPredMode uv_mode =
1469
571k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
571k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
571k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
571k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
571k
                        const enum IntraPredMode m =
1474
571k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
571k
                                                              ypos, ypos > ystart,
1476
571k
                                                              ts->tiling.col_end >> ss_hor,
1477
571k
                                                              ts->tiling.row_end >> ss_ver,
1478
571k
                                                              edge_flags, dst, stride,
1479
571k
                                                              top_sb_edge, uv_mode,
1480
571k
                                                              &angle, uv_t_dim->w,
1481
571k
                                                              uv_t_dim->h,
1482
571k
                                                              f->seq_hdr->intra_edge_filter,
1483
571k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
571k
                        angle |= intra_edge_filter_flag;
1485
571k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
571k
                                                 uv_t_dim->w * 4,
1487
571k
                                                 uv_t_dim->h * 4,
1488
571k
                                                 angle | sm_uv_fl,
1489
571k
                                                 (4 * f->bw + ss_hor -
1490
571k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
571k
                                                 (4 * f->bh + ss_ver -
1492
571k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
571k
                                                 HIGHBD_CALL_SUFFIX);
1494
571k
                        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
603k
                    skip_uv_pred: {}
1505
603k
                        if (!b->skip) {
1506
170k
                            enum TxfmType txtp;
1507
170k
                            int eob;
1508
170k
                            coef *cf;
1509
170k
                            if (t->frame_thread.pass) {
1510
170k
                                const int p = t->frame_thread.pass & 1;
1511
170k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
170k
                                cf = ts->frame_thread[p].cf;
1513
170k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
170k
                                eob  = cbi >> 5;
1515
170k
                                txtp = cbi & 0x1f;
1516
170k
                            } 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
170k
                            if (eob >= 0) {
1533
37.1k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
37.1k
                                dsp->itx.itxfm_add[b->uvtx]
1537
37.1k
                                                  [txtp](dst, stride,
1538
37.1k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
37.1k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
37.1k
                            }
1543
432k
                        } 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
603k
                        dst += uv_t_dim->w * 4;
1548
603k
                    }
1549
349k
                    t->bx -= x << ss_hor;
1550
349k
                }
1551
255k
                t->by -= y << ss_ver;
1552
255k
            }
1553
128k
        }
1554
179k
    }
1555
155k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
94.7k
{
1560
94.7k
    Dav1dTileState *const ts = t->ts;
1561
94.7k
    const Dav1dFrameContext *const f = t->f;
1562
94.7k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
94.7k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
94.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
94.7k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
94.7k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
94.7k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
94.7k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
94.7k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
94.7k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
80.1k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
73.2k
                           (bh4 > ss_ver || t->by & 1);
1573
94.7k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
94.7k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
94.7k
    int res;
1576
1577
    // prediction
1578
94.7k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
94.7k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
94.7k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
94.7k
    const ptrdiff_t uvdstoff =
1582
94.7k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
94.7k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
7.76k
        assert(!f->frame_hdr->super_res.enabled);
1586
7.76k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
7.76k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
7.76k
        if (res) return res;
1589
21.3k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
14.2k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
14.2k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
14.2k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
14.2k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
14.2k
            if (res) return res;
1595
14.2k
        }
1596
86.9k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
70.7k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
70.7k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
70.7k
        if (imin(bw4, bh4) > 1 &&
1601
39.9k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
35.0k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
5.69k
        {
1604
5.69k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
5.69k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
5.69k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
5.69k
            if (res) return res;
1608
65.0k
        } else {
1609
65.0k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
65.0k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
65.0k
            if (res) return res;
1612
65.0k
            if (b->motion_mode == MM_OBMC) {
1613
11.7k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
11.7k
                if (res) return res;
1615
11.7k
            }
1616
65.0k
        }
1617
70.7k
        if (b->interintra_type) {
1618
4.85k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
4.85k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
4.03k
                                   SMOOTH_PRED : b->interintra_mode;
1621
4.85k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
4.85k
            int angle = 0;
1623
4.85k
            const pixel *top_sb_edge = NULL;
1624
4.85k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.16k
                top_sb_edge = f->ipred_edge[0];
1626
1.16k
                const int sby = t->by >> f->sb_shift;
1627
1.16k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.16k
            }
1629
4.85k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
4.85k
                                                  t->by, t->by > ts->tiling.row_start,
1631
4.85k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
4.85k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
4.85k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
4.85k
                                                  HIGHBD_CALL_SUFFIX);
1635
4.85k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
4.85k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
4.85k
                                     HIGHBD_CALL_SUFFIX);
1638
4.85k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
4.85k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
4.85k
        }
1641
1642
70.7k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
48.4k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
48.4k
        refmvs_block *const *r;
1647
48.4k
        if (is_sub8x8) {
1648
8.18k
            assert(ss_hor == 1);
1649
8.18k
            r = &t->rt.r[(t->by & 31) + 5];
1650
8.18k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
8.18k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
8.18k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.00k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
8.18k
        }
1655
1656
        // chroma prediction
1657
48.4k
        if (is_sub8x8) {
1658
8.08k
            assert(ss_hor == 1);
1659
8.08k
            ptrdiff_t h_off = 0, v_off = 0;
1660
8.08k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
5.90k
                for (int pl = 0; pl < 2; pl++) {
1662
3.93k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.93k
                             NULL, f->cur.stride[1],
1664
3.93k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.93k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.93k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.93k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.93k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.93k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.93k
                    if (res) return res;
1671
3.93k
                }
1672
1.96k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.96k
                h_off = 2;
1674
1.96k
            }
1675
8.08k
            if (bw4 == 1) {
1676
4.79k
                const enum Filter2d left_filter_2d =
1677
4.79k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
14.3k
                for (int pl = 0; pl < 2; pl++) {
1679
9.59k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
9.59k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
9.59k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
9.59k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
9.59k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
9.59k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
9.59k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
9.59k
                    if (res) return res;
1687
9.59k
                }
1688
4.79k
                h_off = 2;
1689
4.79k
            }
1690
8.08k
            if (bh4 == ss_ver) {
1691
5.25k
                const enum Filter2d top_filter_2d =
1692
5.25k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
15.7k
                for (int pl = 0; pl < 2; pl++) {
1694
10.5k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
10.5k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
10.5k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
10.5k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
10.5k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
10.5k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
10.5k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
10.5k
                    if (res) return res;
1702
10.5k
                }
1703
5.25k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
5.25k
            }
1705
24.2k
            for (int pl = 0; pl < 2; pl++) {
1706
16.1k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
16.1k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
16.1k
                         refp, b->ref[0], filter_2d);
1709
16.1k
                if (res) return res;
1710
16.1k
            }
1711
40.4k
        } else {
1712
40.4k
            if (imin(cbw4, cbh4) > 1 &&
1713
18.1k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
15.8k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.87k
            {
1716
8.62k
                for (int pl = 0; pl < 2; pl++) {
1717
5.74k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
5.74k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
5.74k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
5.74k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
5.74k
                    if (res) return res;
1722
5.74k
                }
1723
37.5k
            } else {
1724
112k
                for (int pl = 0; pl < 2; pl++) {
1725
75.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
75.0k
                             NULL, f->cur.stride[1],
1727
75.0k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
75.0k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
75.0k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
75.0k
                    if (res) return res;
1731
75.0k
                    if (b->motion_mode == MM_OBMC) {
1732
20.0k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
20.0k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
20.0k
                        if (res) return res;
1735
20.0k
                    }
1736
75.0k
                }
1737
37.5k
            }
1738
40.4k
            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
4.32k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
12.9k
                for (int pl = 0; pl < 2; pl++) {
1745
8.65k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
8.65k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
8.65k
                    enum IntraPredMode m =
1748
8.65k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
7.18k
                        SMOOTH_PRED : b->interintra_mode;
1750
8.65k
                    int angle = 0;
1751
8.65k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
8.65k
                    const pixel *top_sb_edge = NULL;
1753
8.65k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.85k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.85k
                        const int sby = t->by >> f->sb_shift;
1756
1.85k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.85k
                    }
1758
8.65k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
8.65k
                                                          (t->bx >> ss_hor) >
1760
8.65k
                                                              (ts->tiling.col_start >> ss_hor),
1761
8.65k
                                                          t->by >> ss_ver,
1762
8.65k
                                                          (t->by >> ss_ver) >
1763
8.65k
                                                              (ts->tiling.row_start >> ss_ver),
1764
8.65k
                                                          ts->tiling.col_end >> ss_hor,
1765
8.65k
                                                          ts->tiling.row_end >> ss_ver,
1766
8.65k
                                                          0, uvdst, f->cur.stride[1],
1767
8.65k
                                                          top_sb_edge, m,
1768
8.65k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
8.65k
                                                          HIGHBD_CALL_SUFFIX);
1770
8.65k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
8.65k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
8.65k
                                             HIGHBD_CALL_SUFFIX);
1773
8.65k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
8.65k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
8.65k
                }
1776
4.32k
            }
1777
40.4k
        }
1778
1779
70.7k
    skip_inter_chroma_pred: {}
1780
70.7k
        t->tl_4x4_filter = filter_2d;
1781
70.7k
    } else {
1782
16.2k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
16.2k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
16.2k
        int jnt_weight;
1786
16.2k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
16.2k
        const uint8_t *mask;
1788
1789
48.7k
        for (int i = 0; i < 2; i++) {
1790
32.5k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
32.5k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
584
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
584
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
584
                if (res) return res;
1796
31.9k
            } else {
1797
31.9k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
31.9k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
31.9k
                if (res) return res;
1800
31.9k
            }
1801
32.5k
        }
1802
16.2k
        switch (b->comp_type) {
1803
10.7k
        case COMP_INTER_AVG:
1804
10.7k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
10.7k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
10.7k
            break;
1807
1.13k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.13k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.13k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.13k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.13k
            break;
1812
3.03k
        case COMP_INTER_SEG:
1813
3.03k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
3.03k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
3.03k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
3.03k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
3.03k
            mask = seg_mask;
1818
3.03k
            break;
1819
1.30k
        case COMP_INTER_WEDGE:
1820
1.30k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.30k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.30k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.30k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.30k
            if (has_chroma)
1825
1.01k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.30k
            break;
1827
16.2k
        }
1828
1829
        // chroma
1830
36.5k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
73.0k
            for (int i = 0; i < 2; i++) {
1832
48.6k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
48.6k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
5.45k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
566
                {
1836
566
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
566
                                      b_dim, 1 + pl,
1838
566
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
566
                    if (res) return res;
1840
48.1k
                } else {
1841
48.1k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
48.1k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
48.1k
                    if (res) return res;
1844
48.1k
                }
1845
48.6k
            }
1846
24.3k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
24.3k
            switch (b->comp_type) {
1848
16.0k
            case COMP_INTER_AVG:
1849
16.0k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
16.0k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
16.0k
                            HIGHBD_CALL_SUFFIX);
1852
16.0k
                break;
1853
1.80k
            case COMP_INTER_WEIGHTED_AVG:
1854
1.80k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
1.80k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
1.80k
                              HIGHBD_CALL_SUFFIX);
1857
1.80k
                break;
1858
2.03k
            case COMP_INTER_WEDGE:
1859
6.51k
            case COMP_INTER_SEG:
1860
6.51k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
6.51k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
6.51k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
6.51k
                             HIGHBD_CALL_SUFFIX);
1864
6.51k
                break;
1865
24.3k
            }
1866
24.3k
        }
1867
16.2k
    }
1868
1869
94.7k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
94.7k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
94.7k
    if (b->skip) {
1882
        // reset coef contexts
1883
53.3k
        BlockContext *const a = t->a;
1884
53.3k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
53.3k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
53.3k
        if (has_chroma) {
1887
38.8k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
38.8k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
38.8k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
38.8k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
38.8k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
38.8k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
38.8k
        }
1894
53.3k
        return 0;
1895
53.3k
    }
1896
1897
41.3k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
41.3k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
41.3k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
83.4k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
84.8k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
42.7k
            int y_off = !!init_y, y;
1905
42.7k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
86.8k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
44.0k
                 y += ytx->h, y_off++)
1908
44.0k
            {
1909
44.0k
                int x, x_off = !!init_x;
1910
90.9k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
46.9k
                     x += ytx->w, x_off++)
1912
46.9k
                {
1913
46.9k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
46.9k
                                   x_off, y_off, &dst[x * 4]);
1915
46.9k
                    t->bx += ytx->w;
1916
46.9k
                }
1917
44.0k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
44.0k
                t->bx -= x;
1919
44.0k
                t->by += ytx->h;
1920
44.0k
            }
1921
42.7k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
42.7k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
89.9k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
59.9k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
59.9k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
59.9k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
122k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
62.7k
                {
1931
62.7k
                    int x;
1932
62.7k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
127k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
65.1k
                    {
1935
65.1k
                        coef *cf;
1936
65.1k
                        int eob;
1937
65.1k
                        enum TxfmType txtp;
1938
65.1k
                        if (t->frame_thread.pass) {
1939
65.1k
                            const int p = t->frame_thread.pass & 1;
1940
65.1k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
65.1k
                            cf = ts->frame_thread[p].cf;
1942
65.1k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
65.1k
                            eob  = cbi >> 5;
1944
65.1k
                            txtp = cbi & 0x1f;
1945
65.1k
                        } 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
65.1k
                        if (eob >= 0) {
1964
13.2k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
13.2k
                            dsp->itx.itxfm_add[b->uvtx]
1967
13.2k
                                              [txtp](&uvdst[4 * x],
1968
13.2k
                                                     f->cur.stride[1],
1969
13.2k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
13.2k
                            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
13.2k
                        }
1974
65.1k
                        t->bx += uvtx->w << ss_hor;
1975
65.1k
                    }
1976
62.7k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
62.7k
                    t->bx -= x << ss_hor;
1978
62.7k
                    t->by += uvtx->h << ss_ver;
1979
62.7k
                }
1980
59.9k
                t->by -= y << ss_ver;
1981
59.9k
            }
1982
42.7k
        }
1983
42.0k
    }
1984
41.3k
    return 0;
1985
94.7k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
52.2k
{
1560
52.2k
    Dav1dTileState *const ts = t->ts;
1561
52.2k
    const Dav1dFrameContext *const f = t->f;
1562
52.2k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
52.2k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
52.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
52.2k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
52.2k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
52.2k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
52.2k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
52.2k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
52.2k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
44.6k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
40.3k
                           (bh4 > ss_ver || t->by & 1);
1573
52.2k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
52.2k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
52.2k
    int res;
1576
1577
    // prediction
1578
52.2k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
52.2k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
52.2k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
52.2k
    const ptrdiff_t uvdstoff =
1582
52.2k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
52.2k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
4.21k
        assert(!f->frame_hdr->super_res.enabled);
1586
4.21k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
4.21k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
4.21k
        if (res) return res;
1589
12.0k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
8.05k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
8.05k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
8.05k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
8.05k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
8.05k
            if (res) return res;
1595
8.05k
        }
1596
48.0k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
39.0k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
39.0k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
39.0k
        if (imin(bw4, bh4) > 1 &&
1601
21.5k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
17.5k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
4.52k
        {
1604
4.52k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
4.52k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
4.52k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
4.52k
            if (res) return res;
1608
34.4k
        } else {
1609
34.4k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
34.4k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
34.4k
            if (res) return res;
1612
34.4k
            if (b->motion_mode == MM_OBMC) {
1613
5.55k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
5.55k
                if (res) return res;
1615
5.55k
            }
1616
34.4k
        }
1617
39.0k
        if (b->interintra_type) {
1618
2.68k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.68k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
2.23k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.68k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.68k
            int angle = 0;
1623
2.68k
            const pixel *top_sb_edge = NULL;
1624
2.68k
            if (!(t->by & (f->sb_step - 1))) {
1625
557
                top_sb_edge = f->ipred_edge[0];
1626
557
                const int sby = t->by >> f->sb_shift;
1627
557
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
557
            }
1629
2.68k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.68k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.68k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.68k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.68k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.68k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.68k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.68k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.68k
                                     HIGHBD_CALL_SUFFIX);
1638
2.68k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.68k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.68k
        }
1641
1642
39.0k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
26.3k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
26.3k
        refmvs_block *const *r;
1647
26.3k
        if (is_sub8x8) {
1648
4.92k
            assert(ss_hor == 1);
1649
4.92k
            r = &t->rt.r[(t->by & 31) + 5];
1650
4.92k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
4.92k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
4.92k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.25k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
4.92k
        }
1655
1656
        // chroma prediction
1657
26.3k
        if (is_sub8x8) {
1658
4.86k
            assert(ss_hor == 1);
1659
4.86k
            ptrdiff_t h_off = 0, v_off = 0;
1660
4.86k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
3.68k
                for (int pl = 0; pl < 2; pl++) {
1662
2.45k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
2.45k
                             NULL, f->cur.stride[1],
1664
2.45k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
2.45k
                             r[-1][t->bx - 1].mv.mv[0],
1666
2.45k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
2.45k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
2.45k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
2.45k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
2.45k
                    if (res) return res;
1671
2.45k
                }
1672
1.22k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.22k
                h_off = 2;
1674
1.22k
            }
1675
4.86k
            if (bw4 == 1) {
1676
2.92k
                const enum Filter2d left_filter_2d =
1677
2.92k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
8.78k
                for (int pl = 0; pl < 2; pl++) {
1679
5.85k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
5.85k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
5.85k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
5.85k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
5.85k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
5.85k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
5.85k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
5.85k
                    if (res) return res;
1687
5.85k
                }
1688
2.92k
                h_off = 2;
1689
2.92k
            }
1690
4.86k
            if (bh4 == ss_ver) {
1691
3.16k
                const enum Filter2d top_filter_2d =
1692
3.16k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
9.50k
                for (int pl = 0; pl < 2; pl++) {
1694
6.33k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
6.33k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
6.33k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
6.33k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
6.33k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
6.33k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
6.33k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
6.33k
                    if (res) return res;
1702
6.33k
                }
1703
3.16k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
3.16k
            }
1705
14.6k
            for (int pl = 0; pl < 2; pl++) {
1706
9.73k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
9.73k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
9.73k
                         refp, b->ref[0], filter_2d);
1709
9.73k
                if (res) return res;
1710
9.73k
            }
1711
21.5k
        } else {
1712
21.5k
            if (imin(cbw4, cbh4) > 1 &&
1713
9.21k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
7.58k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.91k
            {
1716
5.75k
                for (int pl = 0; pl < 2; pl++) {
1717
3.83k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
3.83k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
3.83k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
3.83k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
3.83k
                    if (res) return res;
1722
3.83k
                }
1723
19.6k
            } else {
1724
58.8k
                for (int pl = 0; pl < 2; pl++) {
1725
39.2k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
39.2k
                             NULL, f->cur.stride[1],
1727
39.2k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
39.2k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
39.2k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
39.2k
                    if (res) return res;
1731
39.2k
                    if (b->motion_mode == MM_OBMC) {
1732
9.48k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
9.48k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
9.48k
                        if (res) return res;
1735
9.48k
                    }
1736
39.2k
                }
1737
19.6k
            }
1738
21.5k
            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
2.46k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
7.39k
                for (int pl = 0; pl < 2; pl++) {
1745
4.93k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
4.93k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
4.93k
                    enum IntraPredMode m =
1748
4.93k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
4.12k
                        SMOOTH_PRED : b->interintra_mode;
1750
4.93k
                    int angle = 0;
1751
4.93k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
4.93k
                    const pixel *top_sb_edge = NULL;
1753
4.93k
                    if (!(t->by & (f->sb_step - 1))) {
1754
984
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
984
                        const int sby = t->by >> f->sb_shift;
1756
984
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
984
                    }
1758
4.93k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
4.93k
                                                          (t->bx >> ss_hor) >
1760
4.93k
                                                              (ts->tiling.col_start >> ss_hor),
1761
4.93k
                                                          t->by >> ss_ver,
1762
4.93k
                                                          (t->by >> ss_ver) >
1763
4.93k
                                                              (ts->tiling.row_start >> ss_ver),
1764
4.93k
                                                          ts->tiling.col_end >> ss_hor,
1765
4.93k
                                                          ts->tiling.row_end >> ss_ver,
1766
4.93k
                                                          0, uvdst, f->cur.stride[1],
1767
4.93k
                                                          top_sb_edge, m,
1768
4.93k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
4.93k
                                                          HIGHBD_CALL_SUFFIX);
1770
4.93k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
4.93k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
4.93k
                                             HIGHBD_CALL_SUFFIX);
1773
4.93k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
4.93k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
4.93k
                }
1776
2.46k
            }
1777
21.5k
        }
1778
1779
38.9k
    skip_inter_chroma_pred: {}
1780
38.9k
        t->tl_4x4_filter = filter_2d;
1781
38.9k
    } else {
1782
9.00k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
9.00k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
9.00k
        int jnt_weight;
1786
9.00k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
9.00k
        const uint8_t *mask;
1788
1789
27.0k
        for (int i = 0; i < 2; i++) {
1790
18.0k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
18.0k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
287
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
287
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
287
                if (res) return res;
1796
17.7k
            } else {
1797
17.7k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
17.7k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
17.7k
                if (res) return res;
1800
17.7k
            }
1801
18.0k
        }
1802
9.00k
        switch (b->comp_type) {
1803
6.02k
        case COMP_INTER_AVG:
1804
6.02k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
6.02k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
6.02k
            break;
1807
563
        case COMP_INTER_WEIGHTED_AVG:
1808
563
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
563
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
563
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
563
            break;
1812
1.72k
        case COMP_INTER_SEG:
1813
1.72k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.72k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.72k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.72k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.72k
            mask = seg_mask;
1818
1.72k
            break;
1819
699
        case COMP_INTER_WEDGE:
1820
699
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
699
            dsp->mc.mask(dst, f->cur.stride[0],
1822
699
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
699
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
699
            if (has_chroma)
1825
559
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
699
            break;
1827
9.00k
        }
1828
1829
        // chroma
1830
20.0k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
40.0k
            for (int i = 0; i < 2; i++) {
1832
26.6k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
26.6k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
2.97k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
222
                {
1836
222
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
222
                                      b_dim, 1 + pl,
1838
222
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
222
                    if (res) return res;
1840
26.4k
                } else {
1841
26.4k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
26.4k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
26.4k
                    if (res) return res;
1844
26.4k
                }
1845
26.6k
            }
1846
13.3k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
13.3k
            switch (b->comp_type) {
1848
8.84k
            case COMP_INTER_AVG:
1849
8.84k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
8.84k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
8.84k
                            HIGHBD_CALL_SUFFIX);
1852
8.84k
                break;
1853
896
            case COMP_INTER_WEIGHTED_AVG:
1854
896
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
896
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
896
                              HIGHBD_CALL_SUFFIX);
1857
896
                break;
1858
1.11k
            case COMP_INTER_WEDGE:
1859
3.59k
            case COMP_INTER_SEG:
1860
3.59k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
3.59k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
3.59k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
3.59k
                             HIGHBD_CALL_SUFFIX);
1864
3.59k
                break;
1865
13.3k
            }
1866
13.3k
        }
1867
9.00k
    }
1868
1869
52.2k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
52.2k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
52.2k
    if (b->skip) {
1882
        // reset coef contexts
1883
30.4k
        BlockContext *const a = t->a;
1884
30.4k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
30.4k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
30.4k
        if (has_chroma) {
1887
22.2k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
22.2k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
22.2k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
22.2k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
22.2k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
22.2k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
22.2k
        }
1894
30.4k
        return 0;
1895
30.4k
    }
1896
1897
21.7k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
21.7k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
21.7k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
43.9k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
44.8k
        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.9k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
23.3k
                 y += ytx->h, y_off++)
1908
23.3k
            {
1909
23.3k
                int x, x_off = !!init_x;
1910
48.6k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
25.2k
                     x += ytx->w, x_off++)
1912
25.2k
                {
1913
25.2k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
25.2k
                                   x_off, y_off, &dst[x * 4]);
1915
25.2k
                    t->bx += ytx->w;
1916
25.2k
                }
1917
23.3k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
23.3k
                t->bx -= x;
1919
23.3k
                t->by += ytx->h;
1920
23.3k
            }
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
46.1k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
30.7k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
30.7k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
30.7k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
63.3k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
32.5k
                {
1931
32.5k
                    int x;
1932
32.5k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
66.5k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
33.9k
                    {
1935
33.9k
                        coef *cf;
1936
33.9k
                        int eob;
1937
33.9k
                        enum TxfmType txtp;
1938
33.9k
                        if (t->frame_thread.pass) {
1939
33.9k
                            const int p = t->frame_thread.pass & 1;
1940
33.9k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
33.9k
                            cf = ts->frame_thread[p].cf;
1942
33.9k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
33.9k
                            eob  = cbi >> 5;
1944
33.9k
                            txtp = cbi & 0x1f;
1945
33.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
33.9k
                        if (eob >= 0) {
1964
6.89k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
6.89k
                            dsp->itx.itxfm_add[b->uvtx]
1967
6.89k
                                              [txtp](&uvdst[4 * x],
1968
6.89k
                                                     f->cur.stride[1],
1969
6.89k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
6.89k
                            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.89k
                        }
1974
33.9k
                        t->bx += uvtx->w << ss_hor;
1975
33.9k
                    }
1976
32.5k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
32.5k
                    t->bx -= x << ss_hor;
1978
32.5k
                    t->by += uvtx->h << ss_ver;
1979
32.5k
                }
1980
30.7k
                t->by -= y << ss_ver;
1981
30.7k
            }
1982
22.5k
        }
1983
22.2k
    }
1984
21.7k
    return 0;
1985
52.2k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
42.5k
{
1560
42.5k
    Dav1dTileState *const ts = t->ts;
1561
42.5k
    const Dav1dFrameContext *const f = t->f;
1562
42.5k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
42.5k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
42.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
42.5k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
42.5k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
42.5k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
42.5k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
42.5k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
42.5k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
35.5k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
32.8k
                           (bh4 > ss_ver || t->by & 1);
1573
42.5k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
42.5k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
42.5k
    int res;
1576
1577
    // prediction
1578
42.5k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
42.5k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
42.5k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
42.5k
    const ptrdiff_t uvdstoff =
1582
42.5k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
42.5k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
3.55k
        assert(!f->frame_hdr->super_res.enabled);
1586
3.55k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
3.55k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
3.55k
        if (res) return res;
1589
9.25k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
6.17k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
6.17k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
6.17k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
6.17k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
6.17k
            if (res) return res;
1595
6.17k
        }
1596
38.9k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
31.7k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
31.7k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
31.7k
        if (imin(bw4, bh4) > 1 &&
1601
18.3k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
17.5k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.16k
        {
1604
1.16k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.16k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.16k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.16k
            if (res) return res;
1608
30.5k
        } else {
1609
30.5k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
30.5k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
30.5k
            if (res) return res;
1612
30.5k
            if (b->motion_mode == MM_OBMC) {
1613
6.17k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
6.17k
                if (res) return res;
1615
6.17k
            }
1616
30.5k
        }
1617
31.7k
        if (b->interintra_type) {
1618
2.16k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.16k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.79k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.16k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.16k
            int angle = 0;
1623
2.16k
            const pixel *top_sb_edge = NULL;
1624
2.16k
            if (!(t->by & (f->sb_step - 1))) {
1625
608
                top_sb_edge = f->ipred_edge[0];
1626
608
                const int sby = t->by >> f->sb_shift;
1627
608
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
608
            }
1629
2.16k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.16k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.16k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.16k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.16k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.16k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.16k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.16k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.16k
                                     HIGHBD_CALL_SUFFIX);
1638
2.16k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.16k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.16k
        }
1641
1642
31.7k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
22.0k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
22.0k
        refmvs_block *const *r;
1647
22.0k
        if (is_sub8x8) {
1648
3.25k
            assert(ss_hor == 1);
1649
3.25k
            r = &t->rt.r[(t->by & 31) + 5];
1650
3.25k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
3.25k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
3.25k
            if (bw4 == 1 && bh4 == ss_ver)
1653
752
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
3.25k
        }
1655
1656
        // chroma prediction
1657
22.0k
        if (is_sub8x8) {
1658
3.21k
            assert(ss_hor == 1);
1659
3.21k
            ptrdiff_t h_off = 0, v_off = 0;
1660
3.21k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
2.22k
                for (int pl = 0; pl < 2; pl++) {
1662
1.48k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.48k
                             NULL, f->cur.stride[1],
1664
1.48k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.48k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.48k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.48k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.48k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.48k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.48k
                    if (res) return res;
1671
1.48k
                }
1672
740
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
740
                h_off = 2;
1674
740
            }
1675
3.21k
            if (bw4 == 1) {
1676
1.87k
                const enum Filter2d left_filter_2d =
1677
1.87k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
5.61k
                for (int pl = 0; pl < 2; pl++) {
1679
3.74k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
3.74k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
3.74k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
3.74k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
3.74k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
3.74k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
3.74k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
3.74k
                    if (res) return res;
1687
3.74k
                }
1688
1.87k
                h_off = 2;
1689
1.87k
            }
1690
3.21k
            if (bh4 == ss_ver) {
1691
2.08k
                const enum Filter2d top_filter_2d =
1692
2.08k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
6.25k
                for (int pl = 0; pl < 2; pl++) {
1694
4.16k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
4.16k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
4.16k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
4.16k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
4.16k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
4.16k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
4.16k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
4.16k
                    if (res) return res;
1702
4.16k
                }
1703
2.08k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
2.08k
            }
1705
9.64k
            for (int pl = 0; pl < 2; pl++) {
1706
6.43k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
6.43k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
6.43k
                         refp, b->ref[0], filter_2d);
1709
6.43k
                if (res) return res;
1710
6.43k
            }
1711
18.8k
        } else {
1712
18.8k
            if (imin(cbw4, cbh4) > 1 &&
1713
8.94k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
8.30k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
956
            {
1716
2.86k
                for (int pl = 0; pl < 2; pl++) {
1717
1.91k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
1.91k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
1.91k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
1.91k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
1.91k
                    if (res) return res;
1722
1.91k
                }
1723
17.9k
            } else {
1724
53.7k
                for (int pl = 0; pl < 2; pl++) {
1725
35.8k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
35.8k
                             NULL, f->cur.stride[1],
1727
35.8k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
35.8k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
35.8k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
35.8k
                    if (res) return res;
1731
35.8k
                    if (b->motion_mode == MM_OBMC) {
1732
10.5k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
10.5k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
10.5k
                        if (res) return res;
1735
10.5k
                    }
1736
35.8k
                }
1737
17.9k
            }
1738
18.8k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
1.86k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
5.58k
                for (int pl = 0; pl < 2; pl++) {
1745
3.72k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
3.72k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
3.72k
                    enum IntraPredMode m =
1748
3.72k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
3.06k
                        SMOOTH_PRED : b->interintra_mode;
1750
3.72k
                    int angle = 0;
1751
3.72k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
3.72k
                    const pixel *top_sb_edge = NULL;
1753
3.72k
                    if (!(t->by & (f->sb_step - 1))) {
1754
874
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
874
                        const int sby = t->by >> f->sb_shift;
1756
874
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
874
                    }
1758
3.72k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
3.72k
                                                          (t->bx >> ss_hor) >
1760
3.72k
                                                              (ts->tiling.col_start >> ss_hor),
1761
3.72k
                                                          t->by >> ss_ver,
1762
3.72k
                                                          (t->by >> ss_ver) >
1763
3.72k
                                                              (ts->tiling.row_start >> ss_ver),
1764
3.72k
                                                          ts->tiling.col_end >> ss_hor,
1765
3.72k
                                                          ts->tiling.row_end >> ss_ver,
1766
3.72k
                                                          0, uvdst, f->cur.stride[1],
1767
3.72k
                                                          top_sb_edge, m,
1768
3.72k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
3.72k
                                                          HIGHBD_CALL_SUFFIX);
1770
3.72k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
3.72k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
3.72k
                                             HIGHBD_CALL_SUFFIX);
1773
3.72k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
3.72k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
3.72k
                }
1776
1.86k
            }
1777
18.8k
        }
1778
1779
31.7k
    skip_inter_chroma_pred: {}
1780
31.7k
        t->tl_4x4_filter = filter_2d;
1781
31.7k
    } else {
1782
7.25k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
7.25k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
7.25k
        int jnt_weight;
1786
7.25k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
7.25k
        const uint8_t *mask;
1788
1789
21.7k
        for (int i = 0; i < 2; i++) {
1790
14.5k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
14.5k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
297
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
297
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
297
                if (res) return res;
1796
14.2k
            } else {
1797
14.2k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
14.2k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
14.2k
                if (res) return res;
1800
14.2k
            }
1801
14.5k
        }
1802
7.25k
        switch (b->comp_type) {
1803
4.76k
        case COMP_INTER_AVG:
1804
4.76k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
4.76k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
4.76k
            break;
1807
574
        case COMP_INTER_WEIGHTED_AVG:
1808
574
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
574
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
574
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
574
            break;
1812
1.30k
        case COMP_INTER_SEG:
1813
1.30k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.30k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.30k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.30k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.30k
            mask = seg_mask;
1818
1.30k
            break;
1819
606
        case COMP_INTER_WEDGE:
1820
606
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
606
            dsp->mc.mask(dst, f->cur.stride[0],
1822
606
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
606
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
606
            if (has_chroma)
1825
456
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
606
            break;
1827
7.25k
        }
1828
1829
        // chroma
1830
16.5k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
33.0k
            for (int i = 0; i < 2; i++) {
1832
22.0k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
22.0k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
2.48k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
344
                {
1836
344
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
344
                                      b_dim, 1 + pl,
1838
344
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
344
                    if (res) return res;
1840
21.6k
                } else {
1841
21.6k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
21.6k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
21.6k
                    if (res) return res;
1844
21.6k
                }
1845
22.0k
            }
1846
11.0k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
11.0k
            switch (b->comp_type) {
1848
7.18k
            case COMP_INTER_AVG:
1849
7.18k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
7.18k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
7.18k
                            HIGHBD_CALL_SUFFIX);
1852
7.18k
                break;
1853
904
            case COMP_INTER_WEIGHTED_AVG:
1854
904
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
904
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
904
                              HIGHBD_CALL_SUFFIX);
1857
904
                break;
1858
912
            case COMP_INTER_WEDGE:
1859
2.92k
            case COMP_INTER_SEG:
1860
2.92k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.92k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.92k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.92k
                             HIGHBD_CALL_SUFFIX);
1864
2.92k
                break;
1865
11.0k
            }
1866
11.0k
        }
1867
7.25k
    }
1868
1869
42.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
42.5k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
42.5k
    if (b->skip) {
1882
        // reset coef contexts
1883
22.9k
        BlockContext *const a = t->a;
1884
22.9k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
22.9k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
22.9k
        if (has_chroma) {
1887
16.5k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
16.5k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
16.5k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
16.5k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
16.5k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
16.5k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
16.5k
        }
1894
22.9k
        return 0;
1895
22.9k
    }
1896
1897
19.5k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
19.5k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
19.5k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
39.4k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
40.0k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
20.1k
            int y_off = !!init_y, y;
1905
20.1k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
40.8k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
20.6k
                 y += ytx->h, y_off++)
1908
20.6k
            {
1909
20.6k
                int x, x_off = !!init_x;
1910
42.3k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
21.6k
                     x += ytx->w, x_off++)
1912
21.6k
                {
1913
21.6k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
21.6k
                                   x_off, y_off, &dst[x * 4]);
1915
21.6k
                    t->bx += ytx->w;
1916
21.6k
                }
1917
20.6k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
20.6k
                t->bx -= x;
1919
20.6k
                t->by += ytx->h;
1920
20.6k
            }
1921
20.1k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
20.1k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
43.8k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
29.2k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
29.2k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
29.2k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
59.4k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
30.1k
                {
1931
30.1k
                    int x;
1932
30.1k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
61.3k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
31.1k
                    {
1935
31.1k
                        coef *cf;
1936
31.1k
                        int eob;
1937
31.1k
                        enum TxfmType txtp;
1938
31.1k
                        if (t->frame_thread.pass) {
1939
31.1k
                            const int p = t->frame_thread.pass & 1;
1940
31.1k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
31.1k
                            cf = ts->frame_thread[p].cf;
1942
31.1k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
31.1k
                            eob  = cbi >> 5;
1944
31.1k
                            txtp = cbi & 0x1f;
1945
31.1k
                        } 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
31.1k
                        if (eob >= 0) {
1964
6.40k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
6.40k
                            dsp->itx.itxfm_add[b->uvtx]
1967
6.40k
                                              [txtp](&uvdst[4 * x],
1968
6.40k
                                                     f->cur.stride[1],
1969
6.40k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
6.40k
                            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.40k
                        }
1974
31.1k
                        t->bx += uvtx->w << ss_hor;
1975
31.1k
                    }
1976
30.1k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
30.1k
                    t->bx -= x << ss_hor;
1978
30.1k
                    t->by += uvtx->h << ss_ver;
1979
30.1k
                }
1980
29.2k
                t->by -= y << ss_ver;
1981
29.2k
            }
1982
20.1k
        }
1983
19.8k
    }
1984
19.5k
    return 0;
1985
42.5k
}
1986
1987
56.4k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
56.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
56.4k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
56.4k
    const int y = sby * f->sb_step * 4;
1994
56.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
56.4k
    pixel *const p[3] = {
1996
56.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
56.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
56.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
56.4k
    };
2000
56.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
56.4k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
56.4k
                                        f->lf.start_of_tile_row[sby]);
2003
56.4k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
27.4k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
27.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
27.4k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
27.4k
    const int y = sby * f->sb_step * 4;
1994
27.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
27.4k
    pixel *const p[3] = {
1996
27.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
27.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
27.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
27.4k
    };
2000
27.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
27.4k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
27.4k
                                        f->lf.start_of_tile_row[sby]);
2003
27.4k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
29.0k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
29.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
29.0k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
29.0k
    const int y = sby * f->sb_step * 4;
1994
29.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
29.0k
    pixel *const p[3] = {
1996
29.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
29.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
29.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
29.0k
    };
2000
29.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
29.0k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
29.0k
                                        f->lf.start_of_tile_row[sby]);
2003
29.0k
}
2004
2005
85.2k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
85.2k
    const int y = sby * f->sb_step * 4;
2007
85.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
85.2k
    pixel *const p[3] = {
2009
85.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
85.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
85.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
85.2k
    };
2013
85.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
85.2k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
85.2k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
56.3k
    {
2017
56.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
56.3k
    }
2019
85.2k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
71.8k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
71.8k
    }
2023
85.2k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
36.2k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
36.2k
    const int y = sby * f->sb_step * 4;
2007
36.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
36.2k
    pixel *const p[3] = {
2009
36.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
36.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
36.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
36.2k
    };
2013
36.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
36.2k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
36.2k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
27.3k
    {
2017
27.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
27.3k
    }
2019
36.2k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
29.9k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
29.9k
    }
2023
36.2k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
48.9k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
48.9k
    const int y = sby * f->sb_step * 4;
2007
48.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
48.9k
    pixel *const p[3] = {
2009
48.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
48.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
48.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
48.9k
    };
2013
48.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
48.9k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
48.9k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
29.0k
    {
2017
29.0k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
29.0k
    }
2019
48.9k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
41.9k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
41.9k
    }
2023
48.9k
}
2024
2025
58.9k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
58.9k
    const Dav1dFrameContext *const f = tc->f;
2027
58.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
58.9k
    const int sbsz = f->sb_step;
2029
58.9k
    const int y = sby * sbsz * 4;
2030
58.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
58.9k
    pixel *const p[3] = {
2032
58.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
58.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
58.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
58.9k
    };
2036
58.9k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
58.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
58.9k
    const int start = sby * sbsz;
2039
58.9k
    if (sby) {
2040
38.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
38.3k
        pixel *p_up[3] = {
2042
38.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
38.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
38.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
38.3k
        };
2046
38.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
38.3k
    }
2048
58.9k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
58.9k
    const int end = imin(start + n_blks, f->bh);
2050
58.9k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
58.9k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
24.9k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
24.9k
    const Dav1dFrameContext *const f = tc->f;
2027
24.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
24.9k
    const int sbsz = f->sb_step;
2029
24.9k
    const int y = sby * sbsz * 4;
2030
24.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
24.9k
    pixel *const p[3] = {
2032
24.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
24.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
24.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
24.9k
    };
2036
24.9k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
24.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
24.9k
    const int start = sby * sbsz;
2039
24.9k
    if (sby) {
2040
15.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
15.8k
        pixel *p_up[3] = {
2042
15.8k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
15.8k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
15.8k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
15.8k
        };
2046
15.8k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
15.8k
    }
2048
24.9k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
24.9k
    const int end = imin(start + n_blks, f->bh);
2050
24.9k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
24.9k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
33.9k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
33.9k
    const Dav1dFrameContext *const f = tc->f;
2027
33.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
33.9k
    const int sbsz = f->sb_step;
2029
33.9k
    const int y = sby * sbsz * 4;
2030
33.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
33.9k
    pixel *const p[3] = {
2032
33.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
33.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
33.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
33.9k
    };
2036
33.9k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
33.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
33.9k
    const int start = sby * sbsz;
2039
33.9k
    if (sby) {
2040
22.4k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
22.4k
        pixel *p_up[3] = {
2042
22.4k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
22.4k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
22.4k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
22.4k
        };
2046
22.4k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
22.4k
    }
2048
33.9k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
33.9k
    const int end = imin(start + n_blks, f->bh);
2050
33.9k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
33.9k
}
2052
2053
21.6k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
21.6k
    const int sbsz = f->sb_step;
2055
21.6k
    const int y = sby * sbsz * 4;
2056
21.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
21.6k
    const pixel *const p[3] = {
2058
21.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
21.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
21.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
21.6k
    };
2062
21.6k
    pixel *const sr_p[3] = {
2063
21.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
21.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
21.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
21.6k
    };
2067
21.6k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
70.6k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
48.9k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
48.9k
        const int h_start = 8 * !!sby >> ss_ver;
2071
48.9k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
48.9k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
48.9k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
48.9k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
48.9k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
48.9k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
48.9k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
48.9k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
48.9k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
48.9k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
48.9k
                          imin(img_h, h_end) + h_start, src_w,
2083
48.9k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
48.9k
                          HIGHBD_CALL_SUFFIX);
2085
48.9k
    }
2086
21.6k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
9.35k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
9.35k
    const int sbsz = f->sb_step;
2055
9.35k
    const int y = sby * sbsz * 4;
2056
9.35k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
9.35k
    const pixel *const p[3] = {
2058
9.35k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
9.35k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
9.35k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
9.35k
    };
2062
9.35k
    pixel *const sr_p[3] = {
2063
9.35k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
9.35k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
9.35k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
9.35k
    };
2067
9.35k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
32.2k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
22.8k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
22.8k
        const int h_start = 8 * !!sby >> ss_ver;
2071
22.8k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
22.8k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
22.8k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
22.8k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
22.8k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
22.8k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
22.8k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
22.8k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
22.8k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
22.8k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
22.8k
                          imin(img_h, h_end) + h_start, src_w,
2083
22.8k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
22.8k
                          HIGHBD_CALL_SUFFIX);
2085
22.8k
    }
2086
9.35k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
12.3k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
12.3k
    const int sbsz = f->sb_step;
2055
12.3k
    const int y = sby * sbsz * 4;
2056
12.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
12.3k
    const pixel *const p[3] = {
2058
12.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
12.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
12.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
12.3k
    };
2062
12.3k
    pixel *const sr_p[3] = {
2063
12.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
12.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
12.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
12.3k
    };
2067
12.3k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
38.3k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
26.0k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
26.0k
        const int h_start = 8 * !!sby >> ss_ver;
2071
26.0k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
26.0k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
26.0k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
26.0k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
26.0k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
26.0k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
26.0k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
26.0k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
26.0k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
26.0k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
26.0k
                          imin(img_h, h_end) + h_start, src_w,
2083
26.0k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
26.0k
                          HIGHBD_CALL_SUFFIX);
2085
26.0k
    }
2086
12.3k
}
2087
2088
33.2k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
33.2k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
33.2k
    const int y = sby * f->sb_step * 4;
2091
33.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
33.2k
    pixel *const sr_p[3] = {
2093
33.2k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
33.2k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
33.2k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
33.2k
    };
2097
33.2k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
33.2k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
13.4k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
13.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
13.4k
    const int y = sby * f->sb_step * 4;
2091
13.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
13.4k
    pixel *const sr_p[3] = {
2093
13.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
13.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
13.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
13.4k
    };
2097
13.4k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
13.4k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
19.8k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
19.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
19.8k
    const int y = sby * f->sb_step * 4;
2091
19.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
19.8k
    pixel *const sr_p[3] = {
2093
19.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
19.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
19.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
19.8k
    };
2097
19.8k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
19.8k
}
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
106k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
106k
    const Dav1dFrameContext *const f = t->f;
2113
106k
    Dav1dTileState *const ts = t->ts;
2114
106k
    const int sby = t->by >> f->sb_shift;
2115
106k
    const int sby_off = f->sb128w * 128 * sby;
2116
106k
    const int x_off = ts->tiling.col_start;
2117
2118
106k
    const pixel *const y =
2119
106k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
106k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
106k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
106k
               4 * (ts->tiling.col_end - x_off));
2123
2124
106k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
70.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
70.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
70.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
70.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
210k
        for (int pl = 1; pl <= 2; pl++)
2131
140k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
61.6k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
61.6k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
70.1k
    }
2135
106k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
49.3k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
49.3k
    const Dav1dFrameContext *const f = t->f;
2113
49.3k
    Dav1dTileState *const ts = t->ts;
2114
49.3k
    const int sby = t->by >> f->sb_shift;
2115
49.3k
    const int sby_off = f->sb128w * 128 * sby;
2116
49.3k
    const int x_off = ts->tiling.col_start;
2117
2118
49.3k
    const pixel *const y =
2119
49.3k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
49.3k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
49.3k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
49.3k
               4 * (ts->tiling.col_end - x_off));
2123
2124
49.3k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
30.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
30.8k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
30.8k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
30.8k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
92.4k
        for (int pl = 1; pl <= 2; pl++)
2131
61.6k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
61.6k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
61.6k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
30.8k
    }
2135
49.3k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
57.4k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
57.4k
    const Dav1dFrameContext *const f = t->f;
2113
57.4k
    Dav1dTileState *const ts = t->ts;
2114
57.4k
    const int sby = t->by >> f->sb_shift;
2115
57.4k
    const int sby_off = f->sb128w * 128 * sby;
2116
57.4k
    const int x_off = ts->tiling.col_start;
2117
2118
57.4k
    const pixel *const y =
2119
57.4k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
57.4k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
57.4k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
57.4k
               4 * (ts->tiling.col_end - x_off));
2123
2124
57.4k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
39.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
39.3k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
39.3k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
39.3k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
117k
        for (int pl = 1; pl <= 2; pl++)
2131
78.6k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
39.3k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
39.3k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
39.3k
    }
2135
57.4k
}
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
15.8k
{
2142
15.8k
    const Dav1dFrameContext *const f = t->f;
2143
15.8k
    pixel *const pal = t->frame_thread.pass ?
2144
15.8k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
15.8k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
15.8k
        bytefn(t->scratch.pal)[0];
2147
78.7k
    for (int x = 0; x < bw4; x++)
2148
62.9k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
64.9k
    for (int y = 0; y < bh4; y++)
2150
49.0k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
15.8k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
7.28k
{
2142
7.28k
    const Dav1dFrameContext *const f = t->f;
2143
7.28k
    pixel *const pal = t->frame_thread.pass ?
2144
7.28k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
7.28k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
7.28k
        bytefn(t->scratch.pal)[0];
2147
36.9k
    for (int x = 0; x < bw4; x++)
2148
29.6k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
29.2k
    for (int y = 0; y < bh4; y++)
2150
21.9k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
7.28k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
8.56k
{
2142
8.56k
    const Dav1dFrameContext *const f = t->f;
2143
8.56k
    pixel *const pal = t->frame_thread.pass ?
2144
8.56k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
8.56k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
8.56k
        bytefn(t->scratch.pal)[0];
2147
41.8k
    for (int x = 0; x < bw4; x++)
2148
33.2k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
35.6k
    for (int y = 0; y < bh4; y++)
2150
27.1k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
8.56k
}
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
5.52k
{
2158
5.52k
    const Dav1dFrameContext *const f = t->f;
2159
5.52k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
5.52k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
5.52k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
5.52k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
16.5k
    for (int pl = 1; pl <= 2; pl++) {
2165
63.6k
        for (int x = 0; x < bw4; x++)
2166
52.6k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
49.4k
        for (int y = 0; y < bh4; y++)
2168
38.4k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
11.0k
    }
2170
5.52k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
1.88k
{
2158
1.88k
    const Dav1dFrameContext *const f = t->f;
2159
1.88k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
1.88k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
1.88k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
1.88k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
5.64k
    for (int pl = 1; pl <= 2; pl++) {
2165
22.1k
        for (int x = 0; x < bw4; x++)
2166
18.4k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
17.5k
        for (int y = 0; y < bh4; y++)
2168
13.7k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
3.76k
    }
2170
1.88k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
3.64k
{
2158
3.64k
    const Dav1dFrameContext *const f = t->f;
2159
3.64k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
3.64k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
3.64k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
3.64k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
10.9k
    for (int pl = 1; pl <= 2; pl++) {
2165
41.4k
        for (int x = 0; x < bw4; x++)
2166
34.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
31.9k
        for (int y = 0; y < bh4; y++)
2168
24.6k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
7.28k
    }
2170
3.64k
}
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
21.3k
{
2176
21.3k
    Dav1dTileState *const ts = t->ts;
2177
21.3k
    const Dav1dFrameContext *const f = t->f;
2178
21.3k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
21.3k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
21.3k
    pixel cache[16], used_cache[8];
2181
21.3k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
21.3k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
21.3k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
21.3k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
21.3k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
35.4k
    while (l_cache && a_cache) {
2190
14.0k
        if (*l < *a) {
2191
4.98k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
4.95k
                cache[n_cache++] = *l;
2193
4.98k
            l++;
2194
4.98k
            l_cache--;
2195
9.09k
        } else {
2196
9.09k
            if (*a == *l) {
2197
3.59k
                l++;
2198
3.59k
                l_cache--;
2199
3.59k
            }
2200
9.09k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
8.77k
                cache[n_cache++] = *a;
2202
9.09k
            a++;
2203
9.09k
            a_cache--;
2204
9.09k
        }
2205
14.0k
    }
2206
21.3k
    if (l_cache) {
2207
26.0k
        do {
2208
26.0k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
21.0k
                cache[n_cache++] = *l;
2210
26.0k
            l++;
2211
26.0k
        } while (--l_cache > 0);
2212
15.1k
    } else if (a_cache) {
2213
18.1k
        do {
2214
18.1k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
14.2k
                cache[n_cache++] = *a;
2216
18.1k
            a++;
2217
18.1k
        } while (--a_cache > 0);
2218
4.51k
    }
2219
2220
    // find reused cache entries
2221
21.3k
    int i = 0;
2222
65.3k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
43.9k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
21.7k
            used_cache[i++] = cache[n];
2225
21.3k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
21.3k
    pixel *const pal = t->frame_thread.pass ?
2229
21.3k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
21.3k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
21.3k
        bytefn(t->scratch.pal)[pl];
2232
21.3k
    if (i < pal_sz) {
2233
18.6k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
18.6k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
18.6k
        if (i < pal_sz) {
2237
16.7k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
16.7k
            const int max = (1 << bpc) - 1;
2239
2240
38.6k
            do {
2241
38.6k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
38.6k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
38.6k
                if (prev + !pl >= max) {
2244
22.4k
                    for (; i < pal_sz; i++)
2245
14.6k
                        pal[i] = max;
2246
7.83k
                    break;
2247
7.83k
                }
2248
30.8k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
30.8k
            } while (i < pal_sz);
2250
16.7k
        }
2251
2252
        // merge cache+new entries
2253
18.6k
        int n = 0, m = n_used_cache;
2254
105k
        for (i = 0; i < pal_sz; i++) {
2255
86.4k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
14.4k
                pal[i] = used_cache[n++];
2257
71.9k
            } else {
2258
71.9k
                assert(m < pal_sz);
2259
71.9k
                pal[i] = pal[m++];
2260
71.9k
            }
2261
86.4k
        }
2262
18.6k
    } else {
2263
2.71k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
2.71k
    }
2265
2266
21.3k
    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
21.3k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
9.17k
{
2176
9.17k
    Dav1dTileState *const ts = t->ts;
2177
9.17k
    const Dav1dFrameContext *const f = t->f;
2178
9.17k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
9.17k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
9.17k
    pixel cache[16], used_cache[8];
2181
9.17k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
9.17k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
9.17k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
9.17k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
9.17k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
16.4k
    while (l_cache && a_cache) {
2190
7.25k
        if (*l < *a) {
2191
2.60k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.59k
                cache[n_cache++] = *l;
2193
2.60k
            l++;
2194
2.60k
            l_cache--;
2195
4.64k
        } else {
2196
4.64k
            if (*a == *l) {
2197
1.84k
                l++;
2198
1.84k
                l_cache--;
2199
1.84k
            }
2200
4.64k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
4.43k
                cache[n_cache++] = *a;
2202
4.64k
            a++;
2203
4.64k
            a_cache--;
2204
4.64k
        }
2205
7.25k
    }
2206
9.17k
    if (l_cache) {
2207
12.2k
        do {
2208
12.2k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
9.74k
                cache[n_cache++] = *l;
2210
12.2k
            l++;
2211
12.2k
        } while (--l_cache > 0);
2212
6.20k
    } else if (a_cache) {
2213
8.12k
        do {
2214
8.12k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
6.16k
                cache[n_cache++] = *a;
2216
8.12k
            a++;
2217
8.12k
        } while (--a_cache > 0);
2218
2.01k
    }
2219
2220
    // find reused cache entries
2221
9.17k
    int i = 0;
2222
29.7k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
20.5k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
10.1k
            used_cache[i++] = cache[n];
2225
9.17k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
9.17k
    pixel *const pal = t->frame_thread.pass ?
2229
9.17k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
9.17k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
9.17k
        bytefn(t->scratch.pal)[pl];
2232
9.17k
    if (i < pal_sz) {
2233
7.97k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
7.97k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
7.97k
        if (i < pal_sz) {
2237
7.05k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
7.05k
            const int max = (1 << bpc) - 1;
2239
2240
15.8k
            do {
2241
15.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
15.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
15.8k
                if (prev + !pl >= max) {
2244
10.1k
                    for (; i < pal_sz; i++)
2245
6.73k
                        pal[i] = max;
2246
3.43k
                    break;
2247
3.43k
                }
2248
12.4k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
12.4k
            } while (i < pal_sz);
2250
7.05k
        }
2251
2252
        // merge cache+new entries
2253
7.97k
        int n = 0, m = n_used_cache;
2254
45.3k
        for (i = 0; i < pal_sz; i++) {
2255
37.3k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
6.82k
                pal[i] = used_cache[n++];
2257
30.5k
            } else {
2258
30.5k
                assert(m < pal_sz);
2259
30.5k
                pal[i] = pal[m++];
2260
30.5k
            }
2261
37.3k
        }
2262
7.97k
    } else {
2263
1.19k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.19k
    }
2265
2266
9.17k
    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
9.17k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
12.2k
{
2176
12.2k
    Dav1dTileState *const ts = t->ts;
2177
12.2k
    const Dav1dFrameContext *const f = t->f;
2178
12.2k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
12.2k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
12.2k
    pixel cache[16], used_cache[8];
2181
12.2k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
12.2k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
12.2k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
12.2k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
12.2k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
19.0k
    while (l_cache && a_cache) {
2190
6.82k
        if (*l < *a) {
2191
2.38k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.36k
                cache[n_cache++] = *l;
2193
2.38k
            l++;
2194
2.38k
            l_cache--;
2195
4.44k
        } else {
2196
4.44k
            if (*a == *l) {
2197
1.74k
                l++;
2198
1.74k
                l_cache--;
2199
1.74k
            }
2200
4.44k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
4.34k
                cache[n_cache++] = *a;
2202
4.44k
            a++;
2203
4.44k
            a_cache--;
2204
4.44k
        }
2205
6.82k
    }
2206
12.2k
    if (l_cache) {
2207
13.8k
        do {
2208
13.8k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
11.3k
                cache[n_cache++] = *l;
2210
13.8k
            l++;
2211
13.8k
        } while (--l_cache > 0);
2212
8.90k
    } else if (a_cache) {
2213
10.0k
        do {
2214
10.0k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
8.13k
                cache[n_cache++] = *a;
2216
10.0k
            a++;
2217
10.0k
        } while (--a_cache > 0);
2218
2.49k
    }
2219
2220
    // find reused cache entries
2221
12.2k
    int i = 0;
2222
35.5k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
23.3k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
11.6k
            used_cache[i++] = cache[n];
2225
12.2k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
12.2k
    pixel *const pal = t->frame_thread.pass ?
2229
12.2k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
12.2k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
12.2k
        bytefn(t->scratch.pal)[pl];
2232
12.2k
    if (i < pal_sz) {
2233
10.6k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
10.6k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
10.6k
        if (i < pal_sz) {
2237
9.71k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
9.71k
            const int max = (1 << bpc) - 1;
2239
2240
22.8k
            do {
2241
22.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
22.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
22.8k
                if (prev + !pl >= max) {
2244
12.2k
                    for (; i < pal_sz; i++)
2245
7.90k
                        pal[i] = max;
2246
4.39k
                    break;
2247
4.39k
                }
2248
18.4k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
18.4k
            } while (i < pal_sz);
2250
9.71k
        }
2251
2252
        // merge cache+new entries
2253
10.6k
        int n = 0, m = n_used_cache;
2254
59.7k
        for (i = 0; i < pal_sz; i++) {
2255
49.0k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
7.65k
                pal[i] = used_cache[n++];
2257
41.4k
            } else {
2258
41.4k
                assert(m < pal_sz);
2259
41.4k
                pal[i] = pal[m++];
2260
41.4k
            }
2261
49.0k
        }
2262
10.6k
    } else {
2263
1.51k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.51k
    }
2265
2266
12.2k
    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
12.2k
}
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
5.52k
{
2281
5.52k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
5.52k
    Dav1dTileState *const ts = t->ts;
2285
5.52k
    const Dav1dFrameContext *const f = t->f;
2286
5.52k
    pixel *const pal = t->frame_thread.pass ?
2287
5.52k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
5.52k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
18.4E
        bytefn(t->scratch.pal)[2];
2290
5.52k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
5.52k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.99k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.99k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.99k
        const int max = (1 << bpc) - 1;
2295
12.4k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
9.45k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
9.45k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
9.45k
            prev = pal[i] = (prev + delta) & max;
2299
9.45k
        }
2300
2.99k
    } else {
2301
13.0k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
10.5k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
2.52k
    }
2304
5.52k
    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
5.52k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
1.88k
{
2281
1.88k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
1.88k
    Dav1dTileState *const ts = t->ts;
2285
1.88k
    const Dav1dFrameContext *const f = t->f;
2286
1.88k
    pixel *const pal = t->frame_thread.pass ?
2287
1.88k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
1.88k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
1.88k
        bytefn(t->scratch.pal)[2];
2290
1.88k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
1.88k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
919
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
919
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
919
        const int max = (1 << bpc) - 1;
2295
4.11k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
3.19k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
3.19k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
3.19k
            prev = pal[i] = (prev + delta) & max;
2299
3.19k
        }
2300
963
    } else {
2301
4.91k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
3.95k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
963
    }
2304
1.88k
    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.88k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
3.64k
{
2281
3.64k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
3.64k
    Dav1dTileState *const ts = t->ts;
2285
3.64k
    const Dav1dFrameContext *const f = t->f;
2286
3.64k
    pixel *const pal = t->frame_thread.pass ?
2287
3.64k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
3.64k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
18.4E
        bytefn(t->scratch.pal)[2];
2290
3.64k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
3.64k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.07k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.07k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.07k
        const int max = (1 << bpc) - 1;
2295
8.33k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
6.25k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
6.25k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
6.25k
            prev = pal[i] = (prev + delta) & max;
2299
6.25k
        }
2300
2.07k
    } else {
2301
8.15k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
6.58k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.56k
    }
2304
3.64k
    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
3.64k
}