Coverage Report

Created: 2026-09-01 06:55

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