Coverage Report

Created: 2026-05-30 06:10

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
365k
static inline unsigned read_golomb(MsacContext *const msac) {
50
365k
    int len = 0;
51
365k
    unsigned val = 1;
52
53
685k
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
685k
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
365k
    return val - 1;
57
365k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
3.02M
{
66
3.02M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
3.02M
    if (chroma) {
69
1.65M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
1.65M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
1.65M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.12M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
1.65M
        unsigned ca, cl;
74
75
1.65M
#define MERGE_CTX(dir, type, no_val) \
76
3.31M
        c##dir = *(const type *) dir != no_val; \
77
3.31M
        break
78
79
1.65M
        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
611k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
370k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
225k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
452k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
1.65M
        }
91
1.65M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
713k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
321k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
177k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
447k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
1.65M
        }
98
1.65M
#undef MERGE_CTX
99
100
1.65M
        return 7 + not_one_blk * 3 + ca + cl;
101
1.65M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
557k
        return 0;
103
809k
    } else {
104
809k
        unsigned la, ll;
105
106
809k
#define MERGE_CTX(dir, type, tx) \
107
1.62M
        if (tx == TX_64X64) { \
108
135k
            uint64_t tmp = *(const uint64_t *) dir; \
109
135k
            tmp |= *(const uint64_t *) &dir[8]; \
110
135k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
135k
        } else \
112
1.62M
            l##dir = *(const type *) dir; \
113
1.62M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
1.62M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
1.62M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
1.62M
        break
117
118
809k
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
324k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
223k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
187k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
10.7k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
67.6k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
809k
        }
126
813k
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
332k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
215k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
187k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
10.4k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
67.6k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
813k
        }
134
813k
#undef MERGE_CTX
135
136
813k
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
813k
    }
138
3.02M
}
139
140
static inline unsigned get_dc_sign_ctx(const int /*enum RectTxfmSize*/ tx,
141
                                       const uint8_t *const a,
142
                                       const uint8_t *const l)
143
1.25M
{
144
1.25M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
1.25M
    int s;
146
147
1.25M
#if ARCH_X86_64 && defined(__GNUC__)
148
    /* Coerce compilers into producing better code. For some reason
149
     * every x86-64 compiler is awful at handling 64-bit constants. */
150
1.25M
    __asm__("" : "+r"(mask), "+r"(mul));
151
1.25M
#endif
152
153
1.25M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
328k
    case TX_4X4: {
156
328k
        int t = *(const uint8_t *) a >> 6;
157
328k
        t    += *(const uint8_t *) l >> 6;
158
328k
        s = t - 1 - 1;
159
328k
        break;
160
0
    }
161
182k
    case TX_8X8: {
162
182k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
182k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
182k
        t *= 0x04040404U;
165
182k
        s = (int) (t >> 24) - 2 - 2;
166
182k
        break;
167
0
    }
168
142k
    case TX_16X16: {
169
142k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
142k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
142k
        t *= (uint32_t) mul;
172
142k
        s = (int) (t >> 24) - 4 - 4;
173
142k
        break;
174
0
    }
175
150k
    case TX_32X32: {
176
150k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
150k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
150k
        t *= mul;
179
150k
        s = (int) (t >> 56) - 8 - 8;
180
150k
        break;
181
0
    }
182
59.4k
    case TX_64X64: {
183
59.4k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
59.4k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
59.4k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
59.4k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
59.4k
        t *= mul;
188
59.4k
        s = (int) (t >> 56) - 16 - 16;
189
59.4k
        break;
190
0
    }
191
46.8k
    case RTX_4X8: {
192
46.8k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
46.8k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
46.8k
        t *= 0x04040404U;
195
46.8k
        s = (int) (t >> 24) - 1 - 2;
196
46.8k
        break;
197
0
    }
198
76.7k
    case RTX_8X4: {
199
76.7k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
76.7k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
76.7k
        t *= 0x04040404U;
202
76.7k
        s = (int) (t >> 24) - 2 - 1;
203
76.7k
        break;
204
0
    }
205
39.7k
    case RTX_8X16: {
206
39.7k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
39.7k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
39.7k
        t = (t >> 6) * (uint32_t) mul;
209
39.7k
        s = (int) (t >> 24) - 2 - 4;
210
39.7k
        break;
211
0
    }
212
58.6k
    case RTX_16X8: {
213
58.6k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
58.6k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
58.6k
        t = (t >> 6) * (uint32_t) mul;
216
58.6k
        s = (int) (t >> 24) - 4 - 2;
217
58.6k
        break;
218
0
    }
219
17.7k
    case RTX_16X32: {
220
17.7k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
17.7k
        t         += *(const uint64_t *) l & mask;
222
17.7k
        t = (t >> 6) * mul;
223
17.7k
        s = (int) (t >> 56) - 4 - 8;
224
17.7k
        break;
225
0
    }
226
22.0k
    case RTX_32X16: {
227
22.0k
        uint64_t t = *(const uint64_t *) a & mask;
228
22.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
22.0k
        t = (t >> 6) * mul;
230
22.0k
        s = (int) (t >> 56) - 8 - 4;
231
22.0k
        break;
232
0
    }
233
10.6k
    case RTX_32X64: {
234
10.6k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
10.6k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
10.6k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
10.6k
        t *= mul;
238
10.6k
        s = (int) (t >> 56) - 8 - 16;
239
10.6k
        break;
240
0
    }
241
5.81k
    case RTX_64X32: {
242
5.81k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
5.81k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
5.81k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
5.81k
        t *= mul;
246
5.81k
        s = (int) (t >> 56) - 16 - 8;
247
5.81k
        break;
248
0
    }
249
22.3k
    case RTX_4X16: {
250
22.3k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
22.3k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
22.3k
        t = (t >> 6) * (uint32_t) mul;
253
22.3k
        s = (int) (t >> 24) - 1 - 4;
254
22.3k
        break;
255
0
    }
256
46.3k
    case RTX_16X4: {
257
46.3k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
46.3k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
46.3k
        t = (t >> 6) * (uint32_t) mul;
260
46.3k
        s = (int) (t >> 24) - 4 - 1;
261
46.3k
        break;
262
0
    }
263
14.1k
    case RTX_8X32: {
264
14.1k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
14.1k
        t         += *(const uint64_t *) l & mask;
266
14.1k
        t = (t >> 6) * mul;
267
14.1k
        s = (int) (t >> 56) - 2 - 8;
268
14.1k
        break;
269
0
    }
270
22.4k
    case RTX_32X8: {
271
22.4k
        uint64_t t = *(const uint64_t *) a & mask;
272
22.4k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
22.4k
        t = (t >> 6) * mul;
274
22.4k
        s = (int) (t >> 56) - 8 - 2;
275
22.4k
        break;
276
0
    }
277
3.30k
    case RTX_16X64: {
278
3.30k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
3.30k
        t         += *(const uint64_t *) &l[0] & mask;
280
3.30k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
3.30k
        t *= mul;
282
3.30k
        s = (int) (t >> 56) - 4 - 16;
283
3.30k
        break;
284
0
    }
285
3.63k
    case RTX_64X16: {
286
3.63k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
3.63k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
3.63k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
3.63k
        t *= mul;
290
3.63k
        s = (int) (t >> 56) - 16 - 4;
291
3.63k
        break;
292
0
    }
293
1.25M
    }
294
295
1.25M
    return (s != 0) + (s > 0);
296
1.25M
}
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
29.1M
{
305
29.1M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
29.1M
    unsigned offset;
307
29.1M
    if (tx_class == TX_CLASS_2D) {
308
27.2M
        mag += levels[1 * stride + 1];
309
27.2M
        *hi_mag = mag;
310
27.2M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
27.2M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
27.2M
    } else {
313
1.88M
        mag += levels[0 * stride + 2];
314
1.88M
        *hi_mag = mag;
315
1.88M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
1.88M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
1.88M
    }
318
29.1M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
29.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
3.02M
{
328
3.02M
    Dav1dTileState *const ts = t->ts;
329
3.02M
    const int chroma = !!plane;
330
3.02M
    const Dav1dFrameContext *const f = t->f;
331
3.02M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
3.02M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
3.02M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
3.02M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
3.02M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
3.02M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
3.02M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
3.02M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
3.02M
    if (all_skip) {
346
1.52M
        *res_ctx = 0x40;
347
1.52M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
1.52M
        return -1;
349
1.52M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
1.50M
    if (lossless) {
353
224k
        assert(t_dim->max == TX_4X4);
354
224k
        *txtp = WHT_WHT;
355
1.28M
    } else if (t_dim->max + intra >= TX_64X64) {
356
319k
        *txtp = DCT_DCT;
357
961k
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
269k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
269k
                        get_uv_inter_txtp(t_dim, *txtp);
361
691k
    } 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
771
        *txtp = DCT_DCT;
366
690k
    } else {
367
690k
        unsigned idx;
368
690k
        if (intra) {
369
597k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
488k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
597k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
242k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
242k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
242k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
355k
            } else {
376
355k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
355k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
355k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
355k
            }
380
597k
            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
597k
        } else {
384
93.3k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
13.8k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
13.8k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
13.8k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
79.5k
            } else if (t_dim->min == TX_16X16) {
389
8.09k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
8.09k
                          ts->cdf.m.txtp_inter2, 11);
391
8.09k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
71.4k
            } else {
393
71.4k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
71.4k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
71.4k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
71.4k
            }
397
93.3k
            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
93.3k
        }
401
690k
    }
402
403
    // find end-of-block (eob)
404
1.50M
    int eob;
405
1.50M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
1.50M
    const int tx2dszctx = slw + slh;
407
1.50M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
1.50M
    const int is_1d = tx_class != TX_CLASS_2D;
409
1.50M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
1.50M
    case sz: { \
412
1.50M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
1.50M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
1.50M
        break; \
415
1.50M
    }
416
388k
    case_sz(0,   16,  8, [is_1d]);
417
158k
    case_sz(1,   32,  8, [is_1d]);
418
320k
    case_sz(2,   64,  8, [is_1d]);
419
127k
    case_sz(3,  128,  8, [is_1d]);
420
220k
    case_sz(4,  256, 16, [is_1d]);
421
53.7k
    case_sz(5,  512, 16,        );
422
239k
    case_sz(6, 1024, 16,        );
423
1.50M
#undef case_sz
424
1.50M
    }
425
1.50M
    if (dbg)
426
0
        printf("Post-eob_bin_%d[%d][%d][%d]: r=%d\n",
427
0
               16 << tx2dszctx, chroma, is_1d, eob, ts->msac.rng);
428
1.50M
    if (eob > 1) {
429
970k
        const int eob_bin = eob - 2;
430
970k
        uint16_t *const eob_hi_bit_cdf =
431
970k
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
970k
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
970k
        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
970k
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
970k
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
970k
    }
440
1.50M
    assert(eob >= 0);
441
442
    // base tokens
443
1.50M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
1.50M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
1.50M
    unsigned rc, dc_tok;
446
447
1.50M
    if (eob) {
448
1.02M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.02M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.02M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.02M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.02M
        int tok = eob_tok + 1;
455
1.02M
        int level_tok = tok * 0x41;
456
1.02M
        unsigned mag;
457
458
1.02M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.02M
        unsigned x, y; \
460
1.02M
        uint8_t *level; \
461
1.02M
        if (tx_class == TX_CLASS_2D) \
462
1.02M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.02M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
85.5k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
85.5k
        else /* tx_class == TX_CLASS_V */ \
467
85.5k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.02M
        if (dbg) \
469
1.02M
            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.02M
        if (eob_tok == 2) { \
472
16.0k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
16.0k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
16.0k
            level_tok = tok + (3 << 6); \
475
16.0k
            if (dbg) \
476
16.0k
                printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
477
0
                       imin(t_dim->ctx, 3), chroma, ctx, eob, rc, tok, \
478
0
                       ts->msac.rng); \
479
16.0k
        } \
480
1.02M
        cf[rc] = tok << 11; \
481
1.02M
        if (tx_class == TX_CLASS_2D) \
482
1.02M
            level = levels + rc; \
483
1.02M
        else \
484
1.02M
            level = levels + x * stride + y; \
485
1.02M
        *level = (uint8_t) level_tok; \
486
30.1M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
29.0M
            unsigned rc_i; \
488
29.0M
            if (tx_class == TX_CLASS_2D) \
489
29.0M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
29.0M
            else if (tx_class == TX_CLASS_H) \
491
1.82M
                x = i & mask, y = i >> shift, rc_i = i; \
492
1.82M
            else /* tx_class == TX_CLASS_V */ \
493
1.82M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
29.0M
            assert(x < 32 && y < 32); \
495
29.0M
            if (tx_class == TX_CLASS_2D) \
496
29.0M
                level = levels + rc_i; \
497
29.0M
            else \
498
29.0M
                level = levels + x * stride + y; \
499
29.0M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
29.0M
            if (tx_class == TX_CLASS_2D) \
501
29.0M
                y |= x; \
502
29.0M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
29.0M
            if (dbg) \
504
29.0M
                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
29.0M
            if (tok == 3) { \
507
2.14M
                mag &= 63; \
508
2.14M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
2.14M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
2.14M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
2.14M
                if (dbg) \
512
2.14M
                    printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
513
0
                           imin(t_dim->ctx, 3), chroma, ctx, i, rc_i, tok, \
514
0
                           ts->msac.rng); \
515
2.14M
                *level = (uint8_t) (tok + (3 << 6)); \
516
2.14M
                cf[rc_i] = (tok << 11) | rc; \
517
2.14M
                rc = rc_i; \
518
26.9M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
26.9M
                tok *= 0x17ff41; \
521
26.9M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
26.9M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
26.9M
                if (tok) rc = rc_i; \
525
26.9M
                cf[rc_i] = tok; \
526
26.9M
            } \
527
29.0M
        } \
528
        /* dc */ \
529
1.02M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.02M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.02M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.02M
        if (dbg) \
533
1.02M
            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.02M
        if (dc_tok == 3) { \
536
364k
            if (tx_class == TX_CLASS_2D) \
537
364k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
354k
                      levels[1 * stride + 1]; \
539
364k
            mag &= 63; \
540
364k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
364k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
364k
            if (dbg) \
543
364k
                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
364k
        } \
546
1.02M
        break
547
548
1.02M
        const uint16_t *scan;
549
1.02M
        switch (tx_class) {
550
938k
        case TX_CLASS_2D: {
551
938k
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
938k
            const uint8_t (*const lo_ctx_offsets)[5] =
553
938k
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
938k
            scan = dav1d_scans[tx];
555
938k
            const ptrdiff_t stride = 4 << slh;
556
938k
            const unsigned shift = slh + 2, shift2 = 0;
557
938k
            const unsigned mask = (4 << slh) - 1;
558
938k
            memset(levels, 0, stride * ((4 << slw) + 2));
559
938k
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
938k
        }
561
56.0k
        case TX_CLASS_H: {
562
56.0k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
56.0k
            const ptrdiff_t stride = 16;
564
56.0k
            const unsigned shift = slh + 2, shift2 = 0;
565
56.0k
            const unsigned mask = (4 << slh) - 1;
566
56.0k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
56.0k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
56.0k
        }
569
29.4k
        case TX_CLASS_V: {
570
29.4k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
29.4k
            const ptrdiff_t stride = 16;
572
29.4k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
29.4k
            const unsigned mask = (4 << slw) - 1;
574
29.4k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
29.4k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
29.4k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.02M
        }
580
1.02M
    } else { // dc-only
581
483k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
483k
        dc_tok = 1 + tok_br;
583
483k
        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
483k
        if (tok_br == 2) {
587
18.3k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
18.3k
            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
18.3k
        }
592
483k
        rc = 0;
593
483k
    }
594
595
    // residual and sign
596
1.50M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
1.50M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
1.50M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
1.50M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
1.50M
    unsigned cul_level, dc_sign_level;
601
602
1.50M
    if (!dc_tok) {
603
255k
        cul_level = 0;
604
255k
        dc_sign_level = 1 << 6;
605
255k
        if (qm_tbl) goto ac_qm;
606
141k
        goto ac_noqm;
607
255k
    }
608
609
1.25M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
1.25M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
1.25M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
1.25M
    if (dbg)
613
0
        printf("Post-dc_sign[%d][%d][%d]: r=%d\n",
614
0
               chroma, dc_sign_ctx, dc_sign, ts->msac.rng);
615
616
1.25M
    int dc_dq = dq_tbl[0];
617
1.25M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
1.25M
    if (qm_tbl) {
620
639k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
639k
        if (dc_tok == 15) {
623
18.4k
            dc_tok = read_golomb(&ts->msac) + 15;
624
18.4k
            if (dbg)
625
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
626
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
627
628
18.4k
            dc_tok &= 0xfffff;
629
18.4k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
621k
        } else {
631
621k
            dc_dq *= dc_tok;
632
621k
            assert(dc_dq <= 0xffffff);
633
621k
        }
634
639k
        cul_level = dc_tok;
635
639k
        dc_dq >>= dq_shift;
636
639k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
639k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
918k
        if (rc) ac_qm: {
640
918k
            const unsigned ac_dq = dq_tbl[1];
641
6.64M
            do {
642
6.64M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
6.64M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
6.64M
                const unsigned rc_tok = cf[rc];
646
6.64M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
6.64M
                int dq_sat;
648
649
6.64M
                if (rc_tok >= (15 << 11)) {
650
270k
                    tok = read_golomb(&ts->msac) + 15;
651
270k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
270k
                    tok &= 0xfffff;
656
270k
                    dq = (dq * tok) & 0xffffff;
657
6.37M
                } else {
658
6.37M
                    tok = rc_tok >> 11;
659
6.37M
                    dq *= tok;
660
6.37M
                    assert(dq <= 0xffffff);
661
6.37M
                }
662
6.64M
                cul_level += tok;
663
6.64M
                dq >>= dq_shift;
664
6.64M
                dq_sat = umin(dq, cf_max + sign);
665
6.64M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
6.64M
                rc = rc_tok & 0x3ff;
668
6.64M
            } while (rc);
669
918k
        }
670
639k
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
613k
        if (dc_tok == 15) {
673
18.0k
            dc_tok = read_golomb(&ts->msac) + 15;
674
18.0k
            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
18.0k
            dc_tok &= 0xfffff;
679
18.0k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
18.0k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
595k
        } else {
682
595k
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
595k
            assert(dc_dq <= cf_max);
684
595k
        }
685
613k
        cul_level = dc_tok;
686
613k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
875k
        if (rc) ac_noqm: {
689
875k
            const unsigned ac_dq = dq_tbl[1];
690
4.41M
            do {
691
4.41M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
4.41M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
4.41M
                const unsigned rc_tok = cf[rc];
695
4.41M
                unsigned tok;
696
4.41M
                int dq;
697
698
                // residual
699
4.41M
                if (rc_tok >= (15 << 11)) {
700
58.3k
                    tok = read_golomb(&ts->msac) + 15;
701
58.3k
                    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
58.3k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
58.3k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
58.3k
                    dq = umin(dq, cf_max + sign);
711
4.35M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
4.35M
                    tok = rc_tok >> 11;
714
4.35M
                    dq = ((ac_dq * tok) >> dq_shift);
715
4.35M
                    assert(dq <= cf_max);
716
4.35M
                }
717
4.41M
                cul_level += tok;
718
4.41M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
4.41M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
4.41M
            } while (rc);
722
875k
        }
723
613k
    }
724
725
    // context
726
1.50M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
1.50M
    return eob;
729
1.25M
}
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
448k
{
737
448k
    const Dav1dFrameContext *const f = t->f;
738
448k
    Dav1dTileState *const ts = t->ts;
739
448k
    const Dav1dDSPContext *const dsp = f->dsp;
740
448k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
448k
    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
448k
    if (depth < 2 && tx_split[depth] &&
746
28.0k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
21.1k
    {
748
21.1k
        const enum RectTxfmSize sub = t_dim->sub;
749
21.1k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
21.1k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
21.1k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
21.1k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
21.1k
        t->bx += txsw;
755
21.1k
        if (txw >= txh && t->bx < f->bw)
756
16.2k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
16.2k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
21.1k
        t->bx -= txsw;
759
21.1k
        t->by += txsh;
760
21.1k
        if (txh >= txw && t->by < f->bh) {
761
14.3k
            if (dst)
762
5.49k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
14.3k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
14.3k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
14.3k
            t->bx += txsw;
766
14.3k
            if (txw >= txh && t->bx < f->bw)
767
9.79k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
9.79k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
14.3k
            t->bx -= txsw;
770
14.3k
        }
771
21.1k
        t->by -= txsh;
772
426k
    } else {
773
426k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
426k
        enum TxfmType txtp;
775
426k
        uint8_t cf_ctx;
776
426k
        int eob;
777
426k
        coef *cf;
778
779
426k
        if (t->frame_thread.pass) {
780
426k
            const int p = t->frame_thread.pass & 1;
781
426k
            assert(ts->frame_thread[p].cf);
782
426k
            cf = ts->frame_thread[p].cf;
783
426k
            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
426k
        if (t->frame_thread.pass != 2) {
788
233k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
233k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
233k
            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
233k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
233k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
233k
#define set_ctx(rep_macro) \
796
1.00M
            for (int y = 0; y < txh; y++) { \
797
773k
                rep_macro(txtp_map, 0, txtp); \
798
773k
                txtp_map += 32; \
799
773k
            }
800
233k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
233k
            case_set_upto16(t_dim->lw);
802
233k
#undef set_ctx
803
233k
            if (t->frame_thread.pass == 1)
804
233k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
233k
        } else {
806
193k
            const int cbi = *ts->frame_thread[0].cbi++;
807
193k
            eob  = cbi >> 5;
808
193k
            txtp = cbi & 0x1f;
809
193k
        }
810
426k
        if (!(t->frame_thread.pass & 1)) {
811
193k
            assert(dst);
812
193k
            if (eob >= 0) {
813
99.8k
                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
99.8k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
99.8k
                                              HIGHBD_CALL_SUFFIX);
817
99.8k
                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
99.8k
            }
820
193k
        }
821
426k
    }
822
448k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
1.75M
{
827
1.75M
    const Dav1dFrameContext *const f = t->f;
828
1.75M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.75M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.75M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.75M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.75M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.75M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.75M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.75M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.68M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.57M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.75M
    if (b->skip) {
840
1.07M
        BlockContext *const a = t->a;
841
1.07M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.07M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.07M
        if (has_chroma) {
844
872k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
872k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
872k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
872k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
872k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
872k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
872k
        }
851
1.07M
        return;
852
1.07M
    }
853
854
681k
    Dav1dTileState *const ts = t->ts;
855
681k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
681k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
681k
    assert(t->frame_thread.pass == 1);
858
681k
    assert(!b->skip);
859
681k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
681k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
681k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.38M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
705k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.43M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
732k
            const int sub_w4 = imin(w4, init_x + 16);
867
732k
            int y_off = !!init_y, y, x;
868
1.59M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
864k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
864k
            {
871
864k
                int x_off = !!init_x;
872
2.20M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.34M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.34M
                {
875
1.34M
                    if (!b->intra) {
876
208k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
208k
                                       x_off, y_off, NULL);
878
1.13M
                    } else {
879
1.13M
                        uint8_t cf_ctx = 0x40;
880
1.13M
                        enum TxfmType txtp;
881
1.13M
                        const int eob =
882
1.13M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.13M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.13M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.13M
                        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.13M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.13M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.13M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.13M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.13M
                    }
893
1.34M
                }
894
864k
                t->bx -= x;
895
864k
            }
896
732k
            t->by -= y;
897
898
732k
            if (!has_chroma) continue;
899
900
630k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
630k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.88M
            for (int pl = 0; pl < 2; pl++) {
903
2.63M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.37M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.37M
                {
906
3.03M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.65M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.65M
                    {
909
1.65M
                        uint8_t cf_ctx = 0x40;
910
1.65M
                        enum TxfmType txtp;
911
1.65M
                        if (!b->intra)
912
387k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
387k
                                                        bx4 + (x << ss_hor)];
914
1.65M
                        const int eob =
915
1.65M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.65M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.65M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.65M
                                         &txtp, &cf_ctx);
919
1.65M
                        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.65M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.65M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.65M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.65M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.65M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.65M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.65M
                    }
930
1.37M
                    t->bx -= x << ss_hor;
931
1.37M
                }
932
1.25M
                t->by -= y << ss_ver;
933
1.25M
            }
934
630k
        }
935
705k
    }
936
681k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
947k
{
827
947k
    const Dav1dFrameContext *const f = t->f;
828
947k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
947k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
947k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
947k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
947k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
947k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
947k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
947k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
911k
                           (bw4 > ss_hor || t->bx & 1) &&
837
851k
                           (bh4 > ss_ver || t->by & 1);
838
839
947k
    if (b->skip) {
840
617k
        BlockContext *const a = t->a;
841
617k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
617k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
617k
        if (has_chroma) {
844
505k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
505k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
505k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
505k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
505k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
505k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
505k
        }
851
617k
        return;
852
617k
    }
853
854
329k
    Dav1dTileState *const ts = t->ts;
855
329k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
329k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
329k
    assert(t->frame_thread.pass == 1);
858
329k
    assert(!b->skip);
859
329k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
329k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
329k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
670k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
340k
        const int sub_h4 = imin(h4, 16 + init_y);
865
692k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
352k
            const int sub_w4 = imin(w4, init_x + 16);
867
352k
            int y_off = !!init_y, y, x;
868
760k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
408k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
408k
            {
871
408k
                int x_off = !!init_x;
872
1.03M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
629k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
629k
                {
875
629k
                    if (!b->intra) {
876
155k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
155k
                                       x_off, y_off, NULL);
878
473k
                    } else {
879
473k
                        uint8_t cf_ctx = 0x40;
880
473k
                        enum TxfmType txtp;
881
473k
                        const int eob =
882
473k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
473k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
473k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
473k
                        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
473k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
473k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
473k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
473k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
473k
                    }
893
629k
                }
894
408k
                t->bx -= x;
895
408k
            }
896
352k
            t->by -= y;
897
898
352k
            if (!has_chroma) continue;
899
900
299k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
299k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
897k
            for (int pl = 0; pl < 2; pl++) {
903
1.26M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
666k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
666k
                {
906
1.52M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
859k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
859k
                    {
909
859k
                        uint8_t cf_ctx = 0x40;
910
859k
                        enum TxfmType txtp;
911
859k
                        if (!b->intra)
912
292k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
292k
                                                        bx4 + (x << ss_hor)];
914
859k
                        const int eob =
915
859k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
859k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
859k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
859k
                                         &txtp, &cf_ctx);
919
859k
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
859k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
859k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
859k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
859k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
859k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
859k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
859k
                    }
930
666k
                    t->bx -= x << ss_hor;
931
666k
                }
932
598k
                t->by -= y << ss_ver;
933
598k
            }
934
299k
        }
935
340k
    }
936
329k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
807k
{
827
807k
    const Dav1dFrameContext *const f = t->f;
828
807k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
807k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
807k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
807k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
807k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
807k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
807k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
807k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
776k
                           (bw4 > ss_hor || t->bx & 1) &&
837
726k
                           (bh4 > ss_ver || t->by & 1);
838
839
807k
    if (b->skip) {
840
455k
        BlockContext *const a = t->a;
841
455k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
455k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
455k
        if (has_chroma) {
844
366k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
366k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
366k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
366k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
366k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
366k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
366k
        }
851
455k
        return;
852
455k
    }
853
854
351k
    Dav1dTileState *const ts = t->ts;
855
351k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
351k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
351k
    assert(t->frame_thread.pass == 1);
858
351k
    assert(!b->skip);
859
351k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
351k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
351k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
715k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
364k
        const int sub_h4 = imin(h4, 16 + init_y);
865
744k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
380k
            const int sub_w4 = imin(w4, init_x + 16);
867
380k
            int y_off = !!init_y, y, x;
868
836k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
456k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
456k
            {
871
456k
                int x_off = !!init_x;
872
1.17M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
716k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
716k
                {
875
716k
                    if (!b->intra) {
876
53.0k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
53.0k
                                       x_off, y_off, NULL);
878
663k
                    } else {
879
663k
                        uint8_t cf_ctx = 0x40;
880
663k
                        enum TxfmType txtp;
881
663k
                        const int eob =
882
663k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
663k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
663k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
663k
                        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
663k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
663k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
663k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
663k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
663k
                    }
893
716k
                }
894
456k
                t->bx -= x;
895
456k
            }
896
380k
            t->by -= y;
897
898
380k
            if (!has_chroma) continue;
899
900
330k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
330k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
991k
            for (int pl = 0; pl < 2; pl++) {
903
1.36M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
707k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
707k
                {
906
1.50M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
799k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
799k
                    {
909
799k
                        uint8_t cf_ctx = 0x40;
910
799k
                        enum TxfmType txtp;
911
799k
                        if (!b->intra)
912
94.4k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
94.4k
                                                        bx4 + (x << ss_hor)];
914
799k
                        const int eob =
915
799k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
799k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
799k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
799k
                                         &txtp, &cf_ctx);
919
799k
                        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
799k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
799k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
799k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
799k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
799k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
799k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
799k
                    }
930
707k
                    t->bx -= x << ss_hor;
931
707k
                }
932
661k
                t->by -= y << ss_ver;
933
661k
            }
934
330k
        }
935
364k
    }
936
351k
}
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
540k
{
945
540k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
540k
    const Dav1dFrameContext *const f = t->f;
947
540k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
540k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
540k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
540k
    const int mvx = mv.x, mvy = mv.y;
951
540k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
540k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
540k
    const pixel *ref;
954
955
540k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
474k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
474k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
474k
        int w, h;
959
960
474k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
365k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
365k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
365k
        } else {
964
108k
            w = f->bw * 4 >> ss_hor;
965
108k
            h = f->bh * 4 >> ss_ver;
966
108k
        }
967
474k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
404k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
319k
            dy + bh4 * v_mul + !!my * 4 > h)
970
217k
        {
971
217k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
217k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
217k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
217k
                                emu_edge_buf, 192 * sizeof(pixel),
975
217k
                                refp->p.data[pl], ref_stride);
976
217k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
217k
            ref_stride = 192 * sizeof(pixel);
978
256k
        } else {
979
256k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
256k
        }
981
982
474k
        if (dst8 != NULL) {
983
432k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
432k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
432k
                                     HIGHBD_CALL_SUFFIX);
986
432k
        } else {
987
42.0k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
42.0k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
42.0k
                                      HIGHBD_CALL_SUFFIX);
990
42.0k
        }
991
474k
    } else {
992
65.8k
        assert(refp != &f->sr_cur);
993
994
65.8k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
65.8k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
131k
#define scale_mv(res, val, scale) do { \
997
131k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
131k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
131k
        } while (0)
1000
65.8k
        int pos_y, pos_x;
1001
65.8k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
65.8k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
65.8k
#undef scale_mv
1004
65.8k
        const int left = pos_x >> 10;
1005
65.8k
        const int top = pos_y >> 10;
1006
65.8k
        const int right =
1007
65.8k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
65.8k
        const int bottom =
1009
65.8k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
65.8k
        if (DEBUG_BLOCK_INFO)
1012
0
            printf("Off %dx%d [%d,%d,%d], size %dx%d [%d,%d]\n",
1013
0
                   left, top, orig_pos_x, f->svc[refidx][0].scale, refidx,
1014
0
                   right-left, bottom-top,
1015
0
                   f->svc[refidx][0].step, f->svc[refidx][1].step);
1016
1017
65.8k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
65.8k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
65.8k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
61.6k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
61.6k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
61.6k
                                w, h, left - 3, top - 3,
1023
61.6k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
61.6k
                                refp->p.data[pl], ref_stride);
1025
61.6k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
61.6k
            ref_stride = 320 * sizeof(pixel);
1027
61.6k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
61.6k
        } else {
1029
4.21k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
4.21k
        }
1031
1032
65.8k
        if (dst8 != NULL) {
1033
51.6k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
51.6k
                                            bw4 * h_mul, bh4 * v_mul,
1035
51.6k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
51.6k
                                            f->svc[refidx][0].step,
1037
51.6k
                                            f->svc[refidx][1].step
1038
51.6k
                                            HIGHBD_CALL_SUFFIX);
1039
51.6k
        } else {
1040
14.2k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
14.2k
                                             bw4 * h_mul, bh4 * v_mul,
1042
14.2k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
14.2k
                                             f->svc[refidx][0].step,
1044
14.2k
                                             f->svc[refidx][1].step
1045
14.2k
                                             HIGHBD_CALL_SUFFIX);
1046
14.2k
        }
1047
65.8k
    }
1048
1049
540k
    return 0;
1050
540k
}
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
56.6k
{
1057
56.6k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
56.6k
    const Dav1dFrameContext *const f = t->f;
1059
56.6k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
56.6k
    pixel *const lap = bitfn(t->scratch.lap);
1061
56.6k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
56.6k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
56.6k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
56.6k
    int res;
1065
1066
56.6k
    if (t->by > t->ts->tiling.row_start &&
1067
47.9k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
47.6k
    {
1069
99.7k
        for (int i = 0, x = 0; x < w4 && i < imin(b_dim[2], 4); ) {
1070
            // only odd blocks are considered for overlap handling, hence +1
1071
52.0k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
52.0k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
52.0k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
52.0k
            if (a_r->ref.ref[0] > 0) {
1076
51.9k
                const int ow4 = imin(step4, b_dim[0]);
1077
51.9k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
51.9k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
51.9k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
51.9k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
51.9k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
51.9k
                if (res) return res;
1083
51.9k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
51.9k
                                   h_mul * ow4, v_mul * oh4);
1085
51.9k
                i++;
1086
51.9k
            }
1087
52.0k
            x += step4;
1088
52.0k
        }
1089
47.6k
    }
1090
1091
56.6k
    if (t->bx > t->ts->tiling.col_start)
1092
104k
        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
53.9k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
53.9k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
53.9k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
53.9k
            if (l_r->ref.ref[0] > 0) {
1099
53.8k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
53.8k
                const int oh4 = imin(step4, b_dim[1]);
1101
53.8k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
53.8k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
53.8k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
53.8k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
53.8k
                if (res) return res;
1106
53.8k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
53.8k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
53.8k
                i++;
1109
53.8k
            }
1110
53.9k
            y += step4;
1111
53.9k
        }
1112
56.6k
    return 0;
1113
56.6k
}
1114
1115
static int warp_affine(Dav1dTaskContext *const t,
1116
                       pixel *dst8, int16_t *dst16, const ptrdiff_t dstride,
1117
                       const uint8_t *const b_dim, const int pl,
1118
                       const Dav1dThreadPicture *const refp,
1119
                       const Dav1dWarpedMotionParams *const wmp)
1120
17.7k
{
1121
17.7k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
17.7k
    const Dav1dFrameContext *const f = t->f;
1123
17.7k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
17.7k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
17.7k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
17.7k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
17.7k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
17.7k
    const int32_t *const mat = wmp->matrix;
1129
17.7k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
17.7k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
57.9k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
40.1k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
40.1k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
40.1k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
248k
        for (int x = 0; x < b_dim[0] * h_mul; x += 8) {
1137
            // calculate transformation relative to center of 8x8 block in
1138
            // luma pixel units
1139
208k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
208k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
208k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
208k
            const int dx = (int) (mvx >> 16) - 4;
1144
208k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
208k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
208k
            const int dy = (int) (mvy >> 16) - 4;
1147
208k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
208k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
208k
            const pixel *ref_ptr;
1151
208k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
208k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
150k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
150k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
150k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
150k
                                    refp->p.data[pl], ref_stride);
1158
150k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
150k
                ref_stride = 32 * sizeof(pixel);
1160
150k
            } else {
1161
57.6k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
57.6k
            }
1163
208k
            if (dst16 != NULL)
1164
23.2k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
23.2k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
185k
            else
1167
185k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
185k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
208k
        }
1170
40.1k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
8.02k
        else      dst16 += 8 * dstride;
1172
40.1k
    }
1173
17.7k
    return 0;
1174
17.7k
}
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.15M
{
1180
1.15M
    Dav1dTileState *const ts = t->ts;
1181
1.15M
    const Dav1dFrameContext *const f = t->f;
1182
1.15M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.15M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.15M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.15M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.15M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.15M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.15M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.15M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.15M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.15M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.11M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.04M
                           (bh4 > ss_ver || t->by & 1);
1194
1.15M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.15M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.15M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.15M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.15M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.32M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.17M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.17M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.38M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.20M
            if (b->pal_sz[0]) {
1208
7.08k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
7.08k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
7.08k
                const uint8_t *pal_idx;
1211
7.08k
                if (t->frame_thread.pass) {
1212
7.08k
                    const int p = t->frame_thread.pass & 1;
1213
7.08k
                    assert(ts->frame_thread[p].pal_idx);
1214
7.08k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
7.08k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
7.08k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
7.08k
                const pixel *const pal = t->frame_thread.pass ?
1220
7.08k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
7.08k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
7.08k
                    bytefn(t->scratch.pal)[0];
1223
7.08k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
7.08k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
7.08k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
7.08k
            }
1229
1230
1.20M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.20M
                                     sm_flag(&t->l, by4) |
1232
1.20M
                                     intra_edge_filter_flag);
1233
1.20M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.17M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.20M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.17M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.20M
            int y, x;
1238
1.20M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.58M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.38M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.38M
            {
1242
1.38M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.38M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.38M
                                    t->bx + init_x);
1245
3.58M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.20M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.19M
                {
1248
2.19M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.18M
                    int angle = b->y_angle;
1251
2.18M
                    const enum EdgeFlags edge_flags =
1252
2.18M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.58M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.18M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.50M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.18M
                    const pixel *top_sb_edge = NULL;
1257
2.18M
                    if (!(t->by & (f->sb_step - 1))) {
1258
387k
                        top_sb_edge = f->ipred_edge[0];
1259
387k
                        const int sby = t->by >> f->sb_shift;
1260
387k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
387k
                    }
1262
2.18M
                    const enum IntraPredMode m =
1263
2.18M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.18M
                                                          t->bx > ts->tiling.col_start,
1265
2.18M
                                                          t->by,
1266
2.18M
                                                          t->by > ts->tiling.row_start,
1267
2.18M
                                                          ts->tiling.col_end,
1268
2.18M
                                                          ts->tiling.row_end,
1269
2.18M
                                                          edge_flags, dst,
1270
2.18M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.18M
                                                          b->y_mode, &angle,
1272
2.18M
                                                          t_dim->w, t_dim->h,
1273
2.18M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.18M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.18M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.18M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.18M
                                             angle | intra_flags,
1278
2.18M
                                             4 * f->bw - 4 * t->bx,
1279
2.18M
                                             4 * f->bh - 4 * t->by
1280
2.18M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.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
2.20M
                skip_y_pred: {}
1293
2.20M
                    if (!b->skip) {
1294
693k
                        coef *cf;
1295
693k
                        int eob;
1296
693k
                        enum TxfmType txtp;
1297
693k
                        if (t->frame_thread.pass) {
1298
693k
                            const int p = t->frame_thread.pass & 1;
1299
693k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
693k
                            cf = ts->frame_thread[p].cf;
1301
693k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
693k
                            eob  = cbi >> 5;
1303
693k
                            txtp = cbi & 0x1f;
1304
693k
                        } 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
693k
                        if (eob >= 0) {
1317
510k
                            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
510k
                            dsp->itx.itxfm_add[b->tx]
1321
510k
                                              [txtp](dst,
1322
510k
                                                     f->cur.stride[0],
1323
510k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
510k
                            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
510k
                        }
1328
1.50M
                    } 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.20M
                    dst += 4 * t_dim->w;
1333
2.20M
                }
1334
1.38M
                t->bx -= x;
1335
1.38M
            }
1336
1.20M
            t->by -= y;
1337
1338
1.20M
            if (!has_chroma) continue;
1339
1340
1.01M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.01M
            if (b->uv_mode == CFL_PRED) {
1343
202k
                assert(!init_x && !init_y);
1344
1345
202k
                int16_t *const ac = t->scratch.ac;
1346
202k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
202k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
202k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
202k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
202k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
202k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
202k
                const int furthest_r =
1354
202k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
202k
                const int furthest_b =
1356
202k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
202k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
202k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
202k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
202k
                                                         cbw4 * 4, cbh4 * 4);
1361
606k
                for (int pl = 0; pl < 2; pl++) {
1362
404k
                    if (!b->cfl_alpha[pl]) continue;
1363
323k
                    int angle = 0;
1364
323k
                    const pixel *top_sb_edge = NULL;
1365
323k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
62.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
62.5k
                        const int sby = t->by >> f->sb_shift;
1368
62.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
62.5k
                    }
1370
323k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
323k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
323k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
323k
                    const enum IntraPredMode m =
1374
323k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
323k
                                                          ypos, ypos > ystart,
1376
323k
                                                          ts->tiling.col_end >> ss_hor,
1377
323k
                                                          ts->tiling.row_end >> ss_ver,
1378
323k
                                                          0, uv_dst[pl], stride,
1379
323k
                                                          top_sb_edge, DC_PRED, &angle,
1380
323k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
323k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
323k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
323k
                                           uv_t_dim->w * 4,
1384
323k
                                           uv_t_dim->h * 4,
1385
323k
                                           ac, b->cfl_alpha[pl]
1386
323k
                                           HIGHBD_CALL_SUFFIX);
1387
323k
                }
1388
202k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
808k
            } else if (b->pal_sz[1]) {
1394
3.28k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.28k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.28k
                const pixel (*pal)[8];
1397
3.28k
                const uint8_t *pal_idx;
1398
3.28k
                if (t->frame_thread.pass) {
1399
3.28k
                    const int p = t->frame_thread.pass & 1;
1400
3.28k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.28k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.28k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.28k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.28k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.28k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.28k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.28k
                                       f->cur.stride[1], pal[1],
1412
3.28k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.28k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.28k
                                       f->cur.stride[1], pal[2],
1415
3.28k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.28k
                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.28k
            }
1425
1426
1.01M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.01M
                                 sm_uv_flag(&t->l, cby4);
1428
1.01M
            const int uv_sb_has_tr =
1429
1.01M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
979k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.01M
            const int uv_sb_has_bl =
1432
1.01M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
979k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.01M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.02M
            for (int pl = 0; pl < 2; pl++) {
1436
4.12M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.11M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.11M
                {
1439
2.11M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.11M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.11M
                                        ((t->bx + init_x) >> ss_hor));
1442
4.54M
                    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.10M
                            b->pal_sz[1])
1447
330k
                        {
1448
330k
                            goto skip_uv_pred;
1449
330k
                        }
1450
1451
2.10M
                        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.10M
                        const enum EdgeFlags edge_flags =
1456
2.10M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
913k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.44M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.10M
                            ((x > (init_x >> ss_hor) ||
1460
1.78M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.33M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.10M
                        const pixel *top_sb_edge = NULL;
1463
2.10M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
569k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
569k
                            const int sby = t->by >> f->sb_shift;
1466
569k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
569k
                        }
1468
2.10M
                        const enum IntraPredMode uv_mode =
1469
2.10M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.10M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.10M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.10M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.10M
                        const enum IntraPredMode m =
1474
2.10M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.10M
                                                              ypos, ypos > ystart,
1476
2.10M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.10M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.10M
                                                              edge_flags, dst, stride,
1479
2.10M
                                                              top_sb_edge, uv_mode,
1480
2.10M
                                                              &angle, uv_t_dim->w,
1481
2.10M
                                                              uv_t_dim->h,
1482
2.10M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.10M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.10M
                        angle |= intra_edge_filter_flag;
1485
2.10M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.10M
                                                 uv_t_dim->w * 4,
1487
2.10M
                                                 uv_t_dim->h * 4,
1488
2.10M
                                                 angle | sm_uv_fl,
1489
2.10M
                                                 (4 * f->bw + ss_hor -
1490
2.10M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.10M
                                                 (4 * f->bh + ss_ver -
1492
2.10M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.10M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.10M
                        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
840k
                            enum TxfmType txtp;
1507
840k
                            int eob;
1508
840k
                            coef *cf;
1509
840k
                            if (t->frame_thread.pass) {
1510
840k
                                const int p = t->frame_thread.pass & 1;
1511
840k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
840k
                                cf = ts->frame_thread[p].cf;
1513
840k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
840k
                                eob  = cbi >> 5;
1515
840k
                                txtp = cbi & 0x1f;
1516
840k
                            } 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
840k
                            if (eob >= 0) {
1533
274k
                                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
274k
                                dsp->itx.itxfm_add[b->uvtx]
1537
274k
                                                  [txtp](dst, stride,
1538
274k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
274k
                                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
274k
                            }
1543
1.59M
                        } 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.11M
                    t->bx -= x << ss_hor;
1550
2.11M
                }
1551
2.01M
                t->by -= y << ss_ver;
1552
2.01M
            }
1553
1.01M
        }
1554
1.17M
    }
1555
1.15M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
605k
{
1180
605k
    Dav1dTileState *const ts = t->ts;
1181
605k
    const Dav1dFrameContext *const f = t->f;
1182
605k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
605k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
605k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
605k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
605k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
605k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
605k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
605k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
605k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
605k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
591k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
548k
                           (bh4 > ss_ver || t->by & 1);
1194
605k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
605k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
605k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
605k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
605k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.22M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
613k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
613k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.24M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
626k
            if (b->pal_sz[0]) {
1208
3.95k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
3.95k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
3.95k
                const uint8_t *pal_idx;
1211
3.95k
                if (t->frame_thread.pass) {
1212
3.95k
                    const int p = t->frame_thread.pass & 1;
1213
3.95k
                    assert(ts->frame_thread[p].pal_idx);
1214
3.95k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
3.95k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
3.95k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
3.95k
                const pixel *const pal = t->frame_thread.pass ?
1220
3.95k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
3.95k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
3.95k
                    bytefn(t->scratch.pal)[0];
1223
3.95k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
3.95k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
3.95k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
3.95k
            }
1229
1230
626k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
626k
                                     sm_flag(&t->l, by4) |
1232
626k
                                     intra_edge_filter_flag);
1233
626k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
613k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
626k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
613k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
626k
            int y, x;
1238
626k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.33M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
705k
                 y += t_dim->h, t->by += t_dim->h)
1241
698k
            {
1242
698k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
698k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
698k
                                    t->bx + init_x);
1245
1.87M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.17M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.16M
                {
1248
1.16M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.16M
                    int angle = b->y_angle;
1251
1.16M
                    const enum EdgeFlags edge_flags =
1252
1.16M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
875k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.16M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
832k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.16M
                    const pixel *top_sb_edge = NULL;
1257
1.16M
                    if (!(t->by & (f->sb_step - 1))) {
1258
217k
                        top_sb_edge = f->ipred_edge[0];
1259
217k
                        const int sby = t->by >> f->sb_shift;
1260
217k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
217k
                    }
1262
1.16M
                    const enum IntraPredMode m =
1263
1.16M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.16M
                                                          t->bx > ts->tiling.col_start,
1265
1.16M
                                                          t->by,
1266
1.16M
                                                          t->by > ts->tiling.row_start,
1267
1.16M
                                                          ts->tiling.col_end,
1268
1.16M
                                                          ts->tiling.row_end,
1269
1.16M
                                                          edge_flags, dst,
1270
1.16M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.16M
                                                          b->y_mode, &angle,
1272
1.16M
                                                          t_dim->w, t_dim->h,
1273
1.16M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.16M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.16M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.16M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.16M
                                             angle | intra_flags,
1278
1.16M
                                             4 * f->bw - 4 * t->bx,
1279
1.16M
                                             4 * f->bh - 4 * t->by
1280
1.16M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.16M
                    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.17M
                skip_y_pred: {}
1293
1.17M
                    if (!b->skip) {
1294
285k
                        coef *cf;
1295
285k
                        int eob;
1296
285k
                        enum TxfmType txtp;
1297
285k
                        if (t->frame_thread.pass) {
1298
285k
                            const int p = t->frame_thread.pass & 1;
1299
285k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
285k
                            cf = ts->frame_thread[p].cf;
1301
285k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
285k
                            eob  = cbi >> 5;
1303
285k
                            txtp = cbi & 0x1f;
1304
285k
                        } 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
285k
                        if (eob >= 0) {
1317
213k
                            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
213k
                            dsp->itx.itxfm_add[b->tx]
1321
213k
                                              [txtp](dst,
1322
213k
                                                     f->cur.stride[0],
1323
213k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
213k
                            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
213k
                        }
1328
887k
                    } 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.17M
                    dst += 4 * t_dim->w;
1333
1.17M
                }
1334
705k
                t->bx -= x;
1335
705k
            }
1336
632k
            t->by -= y;
1337
1338
632k
            if (!has_chroma) continue;
1339
1340
527k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
527k
            if (b->uv_mode == CFL_PRED) {
1343
111k
                assert(!init_x && !init_y);
1344
1345
111k
                int16_t *const ac = t->scratch.ac;
1346
111k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
111k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
111k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
111k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
111k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
111k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
111k
                const int furthest_r =
1354
111k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
111k
                const int furthest_b =
1356
111k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
111k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
111k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
111k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
111k
                                                         cbw4 * 4, cbh4 * 4);
1361
333k
                for (int pl = 0; pl < 2; pl++) {
1362
222k
                    if (!b->cfl_alpha[pl]) continue;
1363
183k
                    int angle = 0;
1364
183k
                    const pixel *top_sb_edge = NULL;
1365
183k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
36.7k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
36.7k
                        const int sby = t->by >> f->sb_shift;
1368
36.7k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
36.7k
                    }
1370
183k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
183k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
183k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
183k
                    const enum IntraPredMode m =
1374
183k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
183k
                                                          ypos, ypos > ystart,
1376
183k
                                                          ts->tiling.col_end >> ss_hor,
1377
183k
                                                          ts->tiling.row_end >> ss_ver,
1378
183k
                                                          0, uv_dst[pl], stride,
1379
183k
                                                          top_sb_edge, DC_PRED, &angle,
1380
183k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
183k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
183k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
183k
                                           uv_t_dim->w * 4,
1384
183k
                                           uv_t_dim->h * 4,
1385
183k
                                           ac, b->cfl_alpha[pl]
1386
183k
                                           HIGHBD_CALL_SUFFIX);
1387
183k
                }
1388
111k
                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
416k
            } else if (b->pal_sz[1]) {
1394
2.17k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.17k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.17k
                const pixel (*pal)[8];
1397
2.17k
                const uint8_t *pal_idx;
1398
2.17k
                if (t->frame_thread.pass) {
1399
2.17k
                    const int p = t->frame_thread.pass & 1;
1400
2.17k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.17k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.17k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.17k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.17k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.17k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.17k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.17k
                                       f->cur.stride[1], pal[1],
1412
2.17k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.17k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.17k
                                       f->cur.stride[1], pal[2],
1415
2.17k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.17k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
2.17k
            }
1425
1426
527k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
527k
                                 sm_uv_flag(&t->l, cby4);
1428
527k
            const int uv_sb_has_tr =
1429
527k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
514k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
527k
            const int uv_sb_has_bl =
1432
527k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
514k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
527k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.57M
            for (int pl = 0; pl < 2; pl++) {
1436
2.14M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.10M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.09M
                {
1439
1.09M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.09M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.09M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.40M
                    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.12M
                            b->pal_sz[1])
1447
187k
                        {
1448
187k
                            goto skip_uv_pred;
1449
187k
                        }
1450
1451
1.11M
                        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.11M
                        const enum EdgeFlags edge_flags =
1456
1.11M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
495k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
797k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.11M
                            ((x > (init_x >> ss_hor) ||
1460
912k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
735k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.11M
                        const pixel *top_sb_edge = NULL;
1463
1.11M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
327k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
327k
                            const int sby = t->by >> f->sb_shift;
1466
327k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
327k
                        }
1468
1.11M
                        const enum IntraPredMode uv_mode =
1469
1.11M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.11M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.11M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.11M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.11M
                        const enum IntraPredMode m =
1474
1.11M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.11M
                                                              ypos, ypos > ystart,
1476
1.11M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.11M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.11M
                                                              edge_flags, dst, stride,
1479
1.11M
                                                              top_sb_edge, uv_mode,
1480
1.11M
                                                              &angle, uv_t_dim->w,
1481
1.11M
                                                              uv_t_dim->h,
1482
1.11M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.11M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.11M
                        angle |= intra_edge_filter_flag;
1485
1.11M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.11M
                                                 uv_t_dim->w * 4,
1487
1.11M
                                                 uv_t_dim->h * 4,
1488
1.11M
                                                 angle | sm_uv_fl,
1489
1.11M
                                                 (4 * f->bw + ss_hor -
1490
1.11M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.11M
                                                 (4 * f->bh + ss_ver -
1492
1.11M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.11M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.11M
                        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
353k
                            enum TxfmType txtp;
1507
353k
                            int eob;
1508
353k
                            coef *cf;
1509
353k
                            if (t->frame_thread.pass) {
1510
353k
                                const int p = t->frame_thread.pass & 1;
1511
353k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
353k
                                cf = ts->frame_thread[p].cf;
1513
353k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
353k
                                eob  = cbi >> 5;
1515
353k
                                txtp = cbi & 0x1f;
1516
353k
                            } 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
353k
                            if (eob >= 0) {
1533
139k
                                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
139k
                                dsp->itx.itxfm_add[b->uvtx]
1537
139k
                                                  [txtp](dst, stride,
1538
139k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
139k
                                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
139k
                            }
1543
951k
                        } 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.10M
                    t->bx -= x << ss_hor;
1550
1.10M
                }
1551
1.04M
                t->by -= y << ss_ver;
1552
1.04M
            }
1553
527k
        }
1554
613k
    }
1555
605k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
546k
{
1180
546k
    Dav1dTileState *const ts = t->ts;
1181
546k
    const Dav1dFrameContext *const f = t->f;
1182
546k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
546k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
546k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
546k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
546k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
546k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
546k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
546k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
546k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
546k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
527k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
492k
                           (bh4 > ss_ver || t->by & 1);
1194
546k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
546k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
546k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
546k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
546k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.10M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
557k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
557k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.13M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
576k
            if (b->pal_sz[0]) {
1208
3.12k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
3.12k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
3.12k
                const uint8_t *pal_idx;
1211
3.12k
                if (t->frame_thread.pass) {
1212
3.12k
                    const int p = t->frame_thread.pass & 1;
1213
3.12k
                    assert(ts->frame_thread[p].pal_idx);
1214
3.12k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
3.12k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
3.12k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
3.12k
                const pixel *const pal = t->frame_thread.pass ?
1220
3.12k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
3.12k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
3.12k
                    bytefn(t->scratch.pal)[0];
1223
3.12k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
3.12k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
3.12k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
3.12k
            }
1229
1230
576k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
576k
                                     sm_flag(&t->l, by4) |
1232
576k
                                     intra_edge_filter_flag);
1233
576k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
557k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
576k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
557k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
576k
            int y, x;
1238
576k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.25M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
681k
                 y += t_dim->h, t->by += t_dim->h)
1241
681k
            {
1242
681k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
681k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
681k
                                    t->bx + init_x);
1245
1.70M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.02M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.02M
                {
1248
1.02M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.02M
                    int angle = b->y_angle;
1251
1.02M
                    const enum EdgeFlags edge_flags =
1252
1.02M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
705k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.02M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
669k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.02M
                    const pixel *top_sb_edge = NULL;
1257
1.02M
                    if (!(t->by & (f->sb_step - 1))) {
1258
170k
                        top_sb_edge = f->ipred_edge[0];
1259
170k
                        const int sby = t->by >> f->sb_shift;
1260
170k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
170k
                    }
1262
1.02M
                    const enum IntraPredMode m =
1263
1.02M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.02M
                                                          t->bx > ts->tiling.col_start,
1265
1.02M
                                                          t->by,
1266
1.02M
                                                          t->by > ts->tiling.row_start,
1267
1.02M
                                                          ts->tiling.col_end,
1268
1.02M
                                                          ts->tiling.row_end,
1269
1.02M
                                                          edge_flags, dst,
1270
1.02M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.02M
                                                          b->y_mode, &angle,
1272
1.02M
                                                          t_dim->w, t_dim->h,
1273
1.02M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.02M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.02M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.02M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.02M
                                             angle | intra_flags,
1278
1.02M
                                             4 * f->bw - 4 * t->bx,
1279
1.02M
                                             4 * f->bh - 4 * t->by
1280
1.02M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.02M
                    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.02M
                skip_y_pred: {}
1293
1.02M
                    if (!b->skip) {
1294
408k
                        coef *cf;
1295
408k
                        int eob;
1296
408k
                        enum TxfmType txtp;
1297
408k
                        if (t->frame_thread.pass) {
1298
408k
                            const int p = t->frame_thread.pass & 1;
1299
408k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
408k
                            cf = ts->frame_thread[p].cf;
1301
408k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
408k
                            eob  = cbi >> 5;
1303
408k
                            txtp = cbi & 0x1f;
1304
408k
                        } 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
408k
                        if (eob >= 0) {
1317
296k
                            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
296k
                            dsp->itx.itxfm_add[b->tx]
1321
296k
                                              [txtp](dst,
1322
296k
                                                     f->cur.stride[0],
1323
296k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
296k
                            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
296k
                        }
1328
620k
                    } 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.02M
                    dst += 4 * t_dim->w;
1333
1.02M
                }
1334
681k
                t->bx -= x;
1335
681k
            }
1336
576k
            t->by -= y;
1337
1338
576k
            if (!has_chroma) continue;
1339
1340
483k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
483k
            if (b->uv_mode == CFL_PRED) {
1343
91.1k
                assert(!init_x && !init_y);
1344
1345
91.1k
                int16_t *const ac = t->scratch.ac;
1346
91.1k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
91.1k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
91.1k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
91.1k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
91.1k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
91.1k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
91.1k
                const int furthest_r =
1354
91.1k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
91.1k
                const int furthest_b =
1356
91.1k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
91.1k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
91.1k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
91.1k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
91.1k
                                                         cbw4 * 4, cbh4 * 4);
1361
273k
                for (int pl = 0; pl < 2; pl++) {
1362
182k
                    if (!b->cfl_alpha[pl]) continue;
1363
140k
                    int angle = 0;
1364
140k
                    const pixel *top_sb_edge = NULL;
1365
140k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
25.7k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
25.7k
                        const int sby = t->by >> f->sb_shift;
1368
25.7k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
25.7k
                    }
1370
140k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
140k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
140k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
140k
                    const enum IntraPredMode m =
1374
140k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
140k
                                                          ypos, ypos > ystart,
1376
140k
                                                          ts->tiling.col_end >> ss_hor,
1377
140k
                                                          ts->tiling.row_end >> ss_ver,
1378
140k
                                                          0, uv_dst[pl], stride,
1379
140k
                                                          top_sb_edge, DC_PRED, &angle,
1380
140k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
140k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
140k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
140k
                                           uv_t_dim->w * 4,
1384
140k
                                           uv_t_dim->h * 4,
1385
140k
                                           ac, b->cfl_alpha[pl]
1386
140k
                                           HIGHBD_CALL_SUFFIX);
1387
140k
                }
1388
91.1k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
392k
            } else if (b->pal_sz[1]) {
1394
1.11k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.11k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.11k
                const pixel (*pal)[8];
1397
1.11k
                const uint8_t *pal_idx;
1398
1.11k
                if (t->frame_thread.pass) {
1399
1.11k
                    const int p = t->frame_thread.pass & 1;
1400
1.11k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.11k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.11k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.11k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.11k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.11k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.11k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.11k
                                       f->cur.stride[1], pal[1],
1412
1.11k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.11k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.11k
                                       f->cur.stride[1], pal[2],
1415
1.11k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.11k
                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.11k
            }
1425
1426
483k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
483k
                                 sm_uv_flag(&t->l, cby4);
1428
483k
            const int uv_sb_has_tr =
1429
483k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
464k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
483k
            const int uv_sb_has_bl =
1432
483k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
464k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
483k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.44M
            for (int pl = 0; pl < 2; pl++) {
1436
1.97M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.01M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.01M
                {
1439
1.01M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.01M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.01M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.14M
                    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
986k
                            b->pal_sz[1])
1447
142k
                        {
1448
142k
                            goto skip_uv_pred;
1449
142k
                        }
1450
1451
983k
                        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
983k
                        const enum EdgeFlags edge_flags =
1456
983k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
418k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
647k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
983k
                            ((x > (init_x >> ss_hor) ||
1460
870k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
597k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
983k
                        const pixel *top_sb_edge = NULL;
1463
983k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
242k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
242k
                            const int sby = t->by >> f->sb_shift;
1466
242k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
242k
                        }
1468
983k
                        const enum IntraPredMode uv_mode =
1469
983k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
983k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
983k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
983k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
983k
                        const enum IntraPredMode m =
1474
983k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
983k
                                                              ypos, ypos > ystart,
1476
983k
                                                              ts->tiling.col_end >> ss_hor,
1477
983k
                                                              ts->tiling.row_end >> ss_ver,
1478
983k
                                                              edge_flags, dst, stride,
1479
983k
                                                              top_sb_edge, uv_mode,
1480
983k
                                                              &angle, uv_t_dim->w,
1481
983k
                                                              uv_t_dim->h,
1482
983k
                                                              f->seq_hdr->intra_edge_filter,
1483
983k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
983k
                        angle |= intra_edge_filter_flag;
1485
983k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
983k
                                                 uv_t_dim->w * 4,
1487
983k
                                                 uv_t_dim->h * 4,
1488
983k
                                                 angle | sm_uv_fl,
1489
983k
                                                 (4 * f->bw + ss_hor -
1490
983k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
983k
                                                 (4 * f->bh + ss_ver -
1492
983k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
983k
                                                 HIGHBD_CALL_SUFFIX);
1494
983k
                        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
486k
                            enum TxfmType txtp;
1507
486k
                            int eob;
1508
486k
                            coef *cf;
1509
486k
                            if (t->frame_thread.pass) {
1510
486k
                                const int p = t->frame_thread.pass & 1;
1511
486k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
486k
                                cf = ts->frame_thread[p].cf;
1513
486k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
486k
                                eob  = cbi >> 5;
1515
486k
                                txtp = cbi & 0x1f;
1516
486k
                            } 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
486k
                            if (eob >= 0) {
1533
134k
                                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
134k
                                dsp->itx.itxfm_add[b->uvtx]
1537
134k
                                                  [txtp](dst, stride,
1538
134k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
134k
                                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
134k
                            }
1543
639k
                        } 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
1.01M
                    t->bx -= x << ss_hor;
1550
1.01M
                }
1551
966k
                t->by -= y << ss_ver;
1552
966k
            }
1553
483k
        }
1554
557k
    }
1555
546k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
154k
{
1560
154k
    Dav1dTileState *const ts = t->ts;
1561
154k
    const Dav1dFrameContext *const f = t->f;
1562
154k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
154k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
154k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
154k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
154k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
154k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
154k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
154k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
154k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
140k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
136k
                           (bh4 > ss_ver || t->by & 1);
1573
154k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
154k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
154k
    int res;
1576
1577
    // prediction
1578
154k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
154k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
154k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
154k
    const ptrdiff_t uvdstoff =
1582
154k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
154k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
43.6k
        assert(!f->frame_hdr->super_res.enabled);
1586
43.6k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
43.6k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
43.6k
        if (res) return res;
1589
96.8k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
64.5k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
64.5k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
64.5k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
64.5k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
64.5k
            if (res) return res;
1595
64.5k
        }
1596
110k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
98.9k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
98.9k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
98.9k
        if (imin(bw4, bh4) > 1 &&
1601
69.7k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
67.4k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
4.29k
        {
1604
4.29k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
4.29k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
4.29k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
4.29k
            if (res) return res;
1608
94.7k
        } else {
1609
94.7k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
94.7k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
94.7k
            if (res) return res;
1612
94.7k
            if (b->motion_mode == MM_OBMC) {
1613
18.9k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
18.9k
                if (res) return res;
1615
18.9k
            }
1616
94.7k
        }
1617
98.9k
        if (b->interintra_type) {
1618
2.03k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.03k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.72k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.03k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.03k
            int angle = 0;
1623
2.03k
            const pixel *top_sb_edge = NULL;
1624
2.03k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.76k
                top_sb_edge = f->ipred_edge[0];
1626
1.76k
                const int sby = t->by >> f->sb_shift;
1627
1.76k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.76k
            }
1629
2.03k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.03k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.03k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.03k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.03k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.03k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.03k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.03k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.03k
                                     HIGHBD_CALL_SUFFIX);
1638
2.03k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.03k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.03k
        }
1641
1642
98.9k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
89.7k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
89.7k
        refmvs_block *const *r;
1647
89.7k
        if (is_sub8x8) {
1648
1.47k
            assert(ss_hor == 1);
1649
1.47k
            r = &t->rt.r[(t->by & 31) + 5];
1650
1.47k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
1.47k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
1.47k
            if (bw4 == 1 && bh4 == ss_ver)
1653
272
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
1.47k
        }
1655
1656
        // chroma prediction
1657
89.7k
        if (is_sub8x8) {
1658
1.47k
            assert(ss_hor == 1);
1659
1.47k
            ptrdiff_t h_off = 0, v_off = 0;
1660
1.47k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
816
                for (int pl = 0; pl < 2; pl++) {
1662
544
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
544
                             NULL, f->cur.stride[1],
1664
544
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
544
                             r[-1][t->bx - 1].mv.mv[0],
1666
544
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
544
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
544
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
544
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
544
                    if (res) return res;
1671
544
                }
1672
272
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
272
                h_off = 2;
1674
272
            }
1675
1.47k
            if (bw4 == 1) {
1676
561
                const enum Filter2d left_filter_2d =
1677
561
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
1.68k
                for (int pl = 0; pl < 2; pl++) {
1679
1.12k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
1.12k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
1.12k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
1.12k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
1.12k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
1.12k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
1.12k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
1.12k
                    if (res) return res;
1687
1.12k
                }
1688
561
                h_off = 2;
1689
561
            }
1690
1.47k
            if (bh4 == ss_ver) {
1691
1.18k
                const enum Filter2d top_filter_2d =
1692
1.18k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
3.54k
                for (int pl = 0; pl < 2; pl++) {
1694
2.36k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
2.36k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
2.36k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
2.36k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
2.36k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
2.36k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
2.36k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
2.36k
                    if (res) return res;
1702
2.36k
                }
1703
1.18k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
1.18k
            }
1705
4.41k
            for (int pl = 0; pl < 2; pl++) {
1706
2.94k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
2.94k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
2.94k
                         refp, b->ref[0], filter_2d);
1709
2.94k
                if (res) return res;
1710
2.94k
            }
1711
88.2k
        } else {
1712
88.2k
            if (imin(cbw4, cbh4) > 1 &&
1713
60.5k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
58.2k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
4.24k
            {
1716
12.7k
                for (int pl = 0; pl < 2; pl++) {
1717
8.49k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
8.49k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
8.49k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
8.49k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
8.49k
                    if (res) return res;
1722
8.49k
                }
1723
84.0k
            } else {
1724
252k
                for (int pl = 0; pl < 2; pl++) {
1725
168k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
168k
                             NULL, f->cur.stride[1],
1727
168k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
168k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
168k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
168k
                    if (res) return res;
1731
168k
                    if (b->motion_mode == MM_OBMC) {
1732
37.7k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
37.7k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
37.7k
                        if (res) return res;
1735
37.7k
                    }
1736
168k
                }
1737
84.0k
            }
1738
88.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
1.73k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
5.19k
                for (int pl = 0; pl < 2; pl++) {
1745
3.46k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
3.46k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
3.46k
                    enum IntraPredMode m =
1748
3.46k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
3.01k
                        SMOOTH_PRED : b->interintra_mode;
1750
3.46k
                    int angle = 0;
1751
3.46k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
3.46k
                    const pixel *top_sb_edge = NULL;
1753
3.46k
                    if (!(t->by & (f->sb_step - 1))) {
1754
2.95k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
2.95k
                        const int sby = t->by >> f->sb_shift;
1756
2.95k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
2.95k
                    }
1758
3.46k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
3.46k
                                                          (t->bx >> ss_hor) >
1760
3.46k
                                                              (ts->tiling.col_start >> ss_hor),
1761
3.46k
                                                          t->by >> ss_ver,
1762
3.46k
                                                          (t->by >> ss_ver) >
1763
3.46k
                                                              (ts->tiling.row_start >> ss_ver),
1764
3.46k
                                                          ts->tiling.col_end >> ss_hor,
1765
3.46k
                                                          ts->tiling.row_end >> ss_ver,
1766
3.46k
                                                          0, uvdst, f->cur.stride[1],
1767
3.46k
                                                          top_sb_edge, m,
1768
3.46k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
3.46k
                                                          HIGHBD_CALL_SUFFIX);
1770
3.46k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
3.46k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
3.46k
                                             HIGHBD_CALL_SUFFIX);
1773
3.46k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
3.46k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
3.46k
                }
1776
1.73k
            }
1777
88.2k
        }
1778
1779
98.9k
    skip_inter_chroma_pred: {}
1780
98.9k
        t->tl_4x4_filter = filter_2d;
1781
98.9k
    } else {
1782
11.5k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
11.5k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
11.5k
        int jnt_weight;
1786
11.5k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
11.5k
        const uint8_t *mask;
1788
1789
34.5k
        for (int i = 0; i < 2; i++) {
1790
23.0k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
23.0k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.72k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.72k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.72k
                if (res) return res;
1796
21.3k
            } else {
1797
21.3k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
21.3k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
21.3k
                if (res) return res;
1800
21.3k
            }
1801
23.0k
        }
1802
11.5k
        switch (b->comp_type) {
1803
9.20k
        case COMP_INTER_AVG:
1804
9.20k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
9.20k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
9.20k
            break;
1807
1.00k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.00k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.00k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.00k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.00k
            break;
1812
990
        case COMP_INTER_SEG:
1813
990
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
990
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
990
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
990
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
990
            mask = seg_mask;
1818
990
            break;
1819
328
        case COMP_INTER_WEDGE:
1820
328
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
328
            dsp->mc.mask(dst, f->cur.stride[0],
1822
328
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
328
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
328
            if (has_chroma)
1825
287
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
328
            break;
1827
11.5k
        }
1828
1829
        // chroma
1830
28.6k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
57.3k
            for (int i = 0; i < 2; i++) {
1832
38.2k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
38.2k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
8.20k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
3.28k
                {
1836
3.28k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
3.28k
                                      b_dim, 1 + pl,
1838
3.28k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
3.28k
                    if (res) return res;
1840
34.9k
                } else {
1841
34.9k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
34.9k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
34.9k
                    if (res) return res;
1844
34.9k
                }
1845
38.2k
            }
1846
19.1k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
19.1k
            switch (b->comp_type) {
1848
16.1k
            case COMP_INTER_AVG:
1849
16.1k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
16.1k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
16.1k
                            HIGHBD_CALL_SUFFIX);
1852
16.1k
                break;
1853
570
            case COMP_INTER_WEIGHTED_AVG:
1854
570
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
570
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
570
                              HIGHBD_CALL_SUFFIX);
1857
570
                break;
1858
574
            case COMP_INTER_WEDGE:
1859
2.35k
            case COMP_INTER_SEG:
1860
2.35k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.35k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.35k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.35k
                             HIGHBD_CALL_SUFFIX);
1864
2.35k
                break;
1865
19.1k
            }
1866
19.1k
        }
1867
11.5k
    }
1868
1869
154k
    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
154k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
154k
    if (b->skip) {
1882
        // reset coef contexts
1883
72.3k
        BlockContext *const a = t->a;
1884
72.3k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
72.3k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
72.3k
        if (has_chroma) {
1887
65.0k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
65.0k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
65.0k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
65.0k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
65.0k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
65.0k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
65.0k
        }
1894
72.3k
        return 0;
1895
72.3k
    }
1896
1897
81.8k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
81.8k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
81.8k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
173k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
183k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
92.5k
            int y_off = !!init_y, y;
1905
92.5k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
200k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
108k
                 y += ytx->h, y_off++)
1908
108k
            {
1909
108k
                int x, x_off = !!init_x;
1910
286k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
178k
                     x += ytx->w, x_off++)
1912
178k
                {
1913
178k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
178k
                                   x_off, y_off, &dst[x * 4]);
1915
178k
                    t->bx += ytx->w;
1916
178k
                }
1917
108k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
108k
                t->bx -= x;
1919
108k
                t->by += ytx->h;
1920
108k
            }
1921
92.5k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
92.5k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
226k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
150k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
150k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
150k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
344k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
193k
                {
1931
193k
                    int x;
1932
193k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
530k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
336k
                    {
1935
336k
                        coef *cf;
1936
336k
                        int eob;
1937
336k
                        enum TxfmType txtp;
1938
336k
                        if (t->frame_thread.pass) {
1939
336k
                            const int p = t->frame_thread.pass & 1;
1940
336k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
336k
                            cf = ts->frame_thread[p].cf;
1942
336k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
336k
                            eob  = cbi >> 5;
1944
336k
                            txtp = cbi & 0x1f;
1945
336k
                        } 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
336k
                        if (eob >= 0) {
1964
131k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
131k
                            dsp->itx.itxfm_add[b->uvtx]
1967
131k
                                              [txtp](&uvdst[4 * x],
1968
131k
                                                     f->cur.stride[1],
1969
131k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
131k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
131k
                        }
1974
336k
                        t->bx += uvtx->w << ss_hor;
1975
336k
                    }
1976
193k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
193k
                    t->bx -= x << ss_hor;
1978
193k
                    t->by += uvtx->h << ss_ver;
1979
193k
                }
1980
150k
                t->by -= y << ss_ver;
1981
150k
            }
1982
92.5k
        }
1983
91.2k
    }
1984
81.8k
    return 0;
1985
154k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
107k
{
1560
107k
    Dav1dTileState *const ts = t->ts;
1561
107k
    const Dav1dFrameContext *const f = t->f;
1562
107k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
107k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
107k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
107k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
107k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
107k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
107k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
107k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
107k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
96.9k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
94.6k
                           (bh4 > ss_ver || t->by & 1);
1573
107k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
107k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
107k
    int res;
1576
1577
    // prediction
1578
107k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
107k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
107k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
107k
    const ptrdiff_t uvdstoff =
1582
107k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
107k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
25.4k
        assert(!f->frame_hdr->super_res.enabled);
1586
25.4k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
25.4k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
25.4k
        if (res) return res;
1589
50.6k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
33.7k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
33.7k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
33.7k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
33.7k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
33.7k
            if (res) return res;
1595
33.7k
        }
1596
81.5k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
75.1k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
75.1k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
75.1k
        if (imin(bw4, bh4) > 1 &&
1601
55.0k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
53.6k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
3.25k
        {
1604
3.25k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
3.25k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
3.25k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
3.25k
            if (res) return res;
1608
71.9k
        } else {
1609
71.9k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
71.9k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
71.9k
            if (res) return res;
1612
71.9k
            if (b->motion_mode == MM_OBMC) {
1613
17.1k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
17.1k
                if (res) return res;
1615
17.1k
            }
1616
71.9k
        }
1617
75.1k
        if (b->interintra_type) {
1618
1.22k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
1.22k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.08k
                                   SMOOTH_PRED : b->interintra_mode;
1621
1.22k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
1.22k
            int angle = 0;
1623
1.22k
            const pixel *top_sb_edge = NULL;
1624
1.22k
            if (!(t->by & (f->sb_step - 1))) {
1625
971
                top_sb_edge = f->ipred_edge[0];
1626
971
                const int sby = t->by >> f->sb_shift;
1627
971
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
971
            }
1629
1.22k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
1.22k
                                                  t->by, t->by > ts->tiling.row_start,
1631
1.22k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
1.22k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
1.22k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
1.22k
                                                  HIGHBD_CALL_SUFFIX);
1635
1.22k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
1.22k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
1.22k
                                     HIGHBD_CALL_SUFFIX);
1638
1.22k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
1.22k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
1.22k
        }
1641
1642
75.1k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
70.4k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
70.4k
        refmvs_block *const *r;
1647
70.4k
        if (is_sub8x8) {
1648
650
            assert(ss_hor == 1);
1649
650
            r = &t->rt.r[(t->by & 31) + 5];
1650
650
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
650
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
650
            if (bw4 == 1 && bh4 == ss_ver)
1653
146
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
650
        }
1655
1656
        // chroma prediction
1657
70.4k
        if (is_sub8x8) {
1658
648
            assert(ss_hor == 1);
1659
648
            ptrdiff_t h_off = 0, v_off = 0;
1660
648
            if (bw4 == 1 && bh4 == ss_ver) {
1661
438
                for (int pl = 0; pl < 2; pl++) {
1662
292
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
292
                             NULL, f->cur.stride[1],
1664
292
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
292
                             r[-1][t->bx - 1].mv.mv[0],
1666
292
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
292
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
292
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
292
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
292
                    if (res) return res;
1671
292
                }
1672
146
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
146
                h_off = 2;
1674
146
            }
1675
648
            if (bw4 == 1) {
1676
328
                const enum Filter2d left_filter_2d =
1677
328
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
984
                for (int pl = 0; pl < 2; pl++) {
1679
656
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
656
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
656
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
656
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
656
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
656
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
656
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
656
                    if (res) return res;
1687
656
                }
1688
328
                h_off = 2;
1689
328
            }
1690
648
            if (bh4 == ss_ver) {
1691
466
                const enum Filter2d top_filter_2d =
1692
466
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
1.39k
                for (int pl = 0; pl < 2; pl++) {
1694
932
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
932
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
932
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
932
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
932
                             r[-1][t->bx].ref.ref[0] - 1,
1699
932
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
932
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
932
                    if (res) return res;
1702
932
                }
1703
466
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
466
            }
1705
1.94k
            for (int pl = 0; pl < 2; pl++) {
1706
1.29k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
1.29k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
1.29k
                         refp, b->ref[0], filter_2d);
1709
1.29k
                if (res) return res;
1710
1.29k
            }
1711
69.7k
        } else {
1712
69.7k
            if (imin(cbw4, cbh4) > 1 &&
1713
49.8k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
48.4k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
3.24k
            {
1716
9.73k
                for (int pl = 0; pl < 2; pl++) {
1717
6.49k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
6.49k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
6.49k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
6.49k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
6.49k
                    if (res) return res;
1722
6.49k
                }
1723
66.5k
            } else {
1724
199k
                for (int pl = 0; pl < 2; pl++) {
1725
133k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
133k
                             NULL, f->cur.stride[1],
1727
133k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
133k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
133k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
133k
                    if (res) return res;
1731
133k
                    if (b->motion_mode == MM_OBMC) {
1732
34.2k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
34.2k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
34.2k
                        if (res) return res;
1735
34.2k
                    }
1736
133k
                }
1737
66.5k
            }
1738
69.7k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
1.04k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
3.13k
                for (int pl = 0; pl < 2; pl++) {
1745
2.08k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
2.08k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
2.08k
                    enum IntraPredMode m =
1748
2.08k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.85k
                        SMOOTH_PRED : b->interintra_mode;
1750
2.08k
                    int angle = 0;
1751
2.08k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
2.08k
                    const pixel *top_sb_edge = NULL;
1753
2.08k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.61k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.61k
                        const int sby = t->by >> f->sb_shift;
1756
1.61k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.61k
                    }
1758
2.08k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
2.08k
                                                          (t->bx >> ss_hor) >
1760
2.08k
                                                              (ts->tiling.col_start >> ss_hor),
1761
2.08k
                                                          t->by >> ss_ver,
1762
2.08k
                                                          (t->by >> ss_ver) >
1763
2.08k
                                                              (ts->tiling.row_start >> ss_ver),
1764
2.08k
                                                          ts->tiling.col_end >> ss_hor,
1765
2.08k
                                                          ts->tiling.row_end >> ss_ver,
1766
2.08k
                                                          0, uvdst, f->cur.stride[1],
1767
2.08k
                                                          top_sb_edge, m,
1768
2.08k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
2.08k
                                                          HIGHBD_CALL_SUFFIX);
1770
2.08k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
2.08k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
2.08k
                                             HIGHBD_CALL_SUFFIX);
1773
2.08k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
2.08k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
2.08k
                }
1776
1.04k
            }
1777
69.7k
        }
1778
1779
75.1k
    skip_inter_chroma_pred: {}
1780
75.1k
        t->tl_4x4_filter = filter_2d;
1781
75.1k
    } else {
1782
6.33k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
6.33k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
6.33k
        int jnt_weight;
1786
6.33k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
6.33k
        const uint8_t *mask;
1788
1789
18.9k
        for (int i = 0; i < 2; i++) {
1790
12.6k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
12.6k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
768
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
768
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
768
                if (res) return res;
1796
11.8k
            } else {
1797
11.8k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
11.8k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
11.8k
                if (res) return res;
1800
11.8k
            }
1801
12.6k
        }
1802
6.33k
        switch (b->comp_type) {
1803
4.98k
        case COMP_INTER_AVG:
1804
4.98k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
4.98k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
4.98k
            break;
1807
497
        case COMP_INTER_WEIGHTED_AVG:
1808
497
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
497
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
497
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
497
            break;
1812
709
        case COMP_INTER_SEG:
1813
709
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
709
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
709
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
709
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
709
            mask = seg_mask;
1818
709
            break;
1819
140
        case COMP_INTER_WEDGE:
1820
140
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
140
            dsp->mc.mask(dst, f->cur.stride[0],
1822
140
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
140
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
140
            if (has_chroma)
1825
101
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
140
            break;
1827
6.33k
        }
1828
1829
        // chroma
1830
14.8k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
29.6k
            for (int i = 0; i < 2; i++) {
1832
19.7k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
19.7k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
3.88k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.44k
                {
1836
1.44k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.44k
                                      b_dim, 1 + pl,
1838
1.44k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.44k
                    if (res) return res;
1840
18.3k
                } else {
1841
18.3k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
18.3k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
18.3k
                    if (res) return res;
1844
18.3k
                }
1845
19.7k
            }
1846
9.89k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
9.89k
            switch (b->comp_type) {
1848
8.28k
            case COMP_INTER_AVG:
1849
8.28k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
8.28k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
8.28k
                            HIGHBD_CALL_SUFFIX);
1852
8.28k
                break;
1853
168
            case COMP_INTER_WEIGHTED_AVG:
1854
168
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
168
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
168
                              HIGHBD_CALL_SUFFIX);
1857
168
                break;
1858
202
            case COMP_INTER_WEDGE:
1859
1.44k
            case COMP_INTER_SEG:
1860
1.44k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
1.44k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
1.44k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
1.44k
                             HIGHBD_CALL_SUFFIX);
1864
1.44k
                break;
1865
9.89k
            }
1866
9.89k
        }
1867
6.33k
    }
1868
1869
107k
    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
107k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
107k
    if (b->skip) {
1882
        // reset coef contexts
1883
57.6k
        BlockContext *const a = t->a;
1884
57.6k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
57.6k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
57.6k
        if (has_chroma) {
1887
52.0k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
52.0k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
52.0k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
52.0k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
52.0k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
52.0k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
52.0k
        }
1894
57.6k
        return 0;
1895
57.6k
    }
1896
1897
49.3k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
49.3k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
49.3k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
103k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
109k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
55.3k
            int y_off = !!init_y, y;
1905
55.3k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
125k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
70.5k
                 y += ytx->h, y_off++)
1908
70.5k
            {
1909
70.5k
                int x, x_off = !!init_x;
1910
208k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
138k
                     x += ytx->w, x_off++)
1912
138k
                {
1913
138k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
138k
                                   x_off, y_off, &dst[x * 4]);
1915
138k
                    t->bx += ytx->w;
1916
138k
                }
1917
70.5k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
70.5k
                t->bx -= x;
1919
70.5k
                t->by += ytx->h;
1920
70.5k
            }
1921
55.3k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
55.3k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
135k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
90.6k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
90.6k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
90.6k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
217k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
127k
                {
1931
127k
                    int x;
1932
127k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
391k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
264k
                    {
1935
264k
                        coef *cf;
1936
264k
                        int eob;
1937
264k
                        enum TxfmType txtp;
1938
264k
                        if (t->frame_thread.pass) {
1939
264k
                            const int p = t->frame_thread.pass & 1;
1940
264k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
264k
                            cf = ts->frame_thread[p].cf;
1942
264k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
264k
                            eob  = cbi >> 5;
1944
264k
                            txtp = cbi & 0x1f;
1945
264k
                        } 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
264k
                        if (eob >= 0) {
1964
114k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
114k
                            dsp->itx.itxfm_add[b->uvtx]
1967
114k
                                              [txtp](&uvdst[4 * x],
1968
114k
                                                     f->cur.stride[1],
1969
114k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
114k
                            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
114k
                        }
1974
264k
                        t->bx += uvtx->w << ss_hor;
1975
264k
                    }
1976
127k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
127k
                    t->bx -= x << ss_hor;
1978
127k
                    t->by += uvtx->h << ss_ver;
1979
127k
                }
1980
90.6k
                t->by -= y << ss_ver;
1981
90.6k
            }
1982
55.3k
        }
1983
54.4k
    }
1984
49.3k
    return 0;
1985
107k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
47.1k
{
1560
47.1k
    Dav1dTileState *const ts = t->ts;
1561
47.1k
    const Dav1dFrameContext *const f = t->f;
1562
47.1k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
47.1k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
47.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
47.1k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
47.1k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
47.1k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
47.1k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
47.1k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
47.1k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
43.1k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
41.5k
                           (bh4 > ss_ver || t->by & 1);
1573
47.1k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
47.1k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
47.1k
    int res;
1576
1577
    // prediction
1578
47.1k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
47.1k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
47.1k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
47.1k
    const ptrdiff_t uvdstoff =
1582
47.1k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
47.1k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
18.1k
        assert(!f->frame_hdr->super_res.enabled);
1586
18.1k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
18.1k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
18.1k
        if (res) return res;
1589
46.2k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
30.8k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
30.8k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
30.8k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
30.8k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
30.8k
            if (res) return res;
1595
30.8k
        }
1596
28.9k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
23.7k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
23.7k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
23.7k
        if (imin(bw4, bh4) > 1 &&
1601
14.6k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
13.7k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.03k
        {
1604
1.03k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.03k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.03k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.03k
            if (res) return res;
1608
22.7k
        } else {
1609
22.7k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
22.7k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
22.7k
            if (res) return res;
1612
22.7k
            if (b->motion_mode == MM_OBMC) {
1613
1.78k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
1.78k
                if (res) return res;
1615
1.78k
            }
1616
22.7k
        }
1617
23.7k
        if (b->interintra_type) {
1618
814
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
814
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
636
                                   SMOOTH_PRED : b->interintra_mode;
1621
814
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
814
            int angle = 0;
1623
814
            const pixel *top_sb_edge = NULL;
1624
814
            if (!(t->by & (f->sb_step - 1))) {
1625
792
                top_sb_edge = f->ipred_edge[0];
1626
792
                const int sby = t->by >> f->sb_shift;
1627
792
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
792
            }
1629
814
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
814
                                                  t->by, t->by > ts->tiling.row_start,
1631
814
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
814
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
814
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
814
                                                  HIGHBD_CALL_SUFFIX);
1635
814
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
814
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
814
                                     HIGHBD_CALL_SUFFIX);
1638
814
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
814
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
814
        }
1641
1642
23.7k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
19.3k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
19.3k
        refmvs_block *const *r;
1647
19.3k
        if (is_sub8x8) {
1648
829
            assert(ss_hor == 1);
1649
829
            r = &t->rt.r[(t->by & 31) + 5];
1650
829
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
829
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
829
            if (bw4 == 1 && bh4 == ss_ver)
1653
126
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
829
        }
1655
1656
        // chroma prediction
1657
19.3k
        if (is_sub8x8) {
1658
823
            assert(ss_hor == 1);
1659
823
            ptrdiff_t h_off = 0, v_off = 0;
1660
823
            if (bw4 == 1 && bh4 == ss_ver) {
1661
378
                for (int pl = 0; pl < 2; pl++) {
1662
252
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
252
                             NULL, f->cur.stride[1],
1664
252
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
252
                             r[-1][t->bx - 1].mv.mv[0],
1666
252
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
252
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
252
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
252
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
252
                    if (res) return res;
1671
252
                }
1672
126
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
126
                h_off = 2;
1674
126
            }
1675
823
            if (bw4 == 1) {
1676
233
                const enum Filter2d left_filter_2d =
1677
233
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
699
                for (int pl = 0; pl < 2; pl++) {
1679
466
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
466
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
466
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
466
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
466
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
466
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
466
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
466
                    if (res) return res;
1687
466
                }
1688
233
                h_off = 2;
1689
233
            }
1690
823
            if (bh4 == ss_ver) {
1691
716
                const enum Filter2d top_filter_2d =
1692
716
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
2.14k
                for (int pl = 0; pl < 2; pl++) {
1694
1.43k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
1.43k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
1.43k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
1.43k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
1.43k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
1.43k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
1.43k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
1.43k
                    if (res) return res;
1702
1.43k
                }
1703
716
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
716
            }
1705
2.46k
            for (int pl = 0; pl < 2; pl++) {
1706
1.64k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
1.64k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
1.64k
                         refp, b->ref[0], filter_2d);
1709
1.64k
                if (res) return res;
1710
1.64k
            }
1711
18.5k
        } else {
1712
18.5k
            if (imin(cbw4, cbh4) > 1 &&
1713
10.6k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
9.81k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.00k
            {
1716
3.00k
                for (int pl = 0; pl < 2; pl++) {
1717
2.00k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
2.00k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
2.00k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
2.00k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
2.00k
                    if (res) return res;
1722
2.00k
                }
1723
17.5k
            } else {
1724
52.5k
                for (int pl = 0; pl < 2; pl++) {
1725
35.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
35.0k
                             NULL, f->cur.stride[1],
1727
35.0k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
35.0k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
35.0k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
35.0k
                    if (res) return res;
1731
35.0k
                    if (b->motion_mode == MM_OBMC) {
1732
3.48k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
3.48k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
3.48k
                        if (res) return res;
1735
3.48k
                    }
1736
35.0k
                }
1737
17.5k
            }
1738
18.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
689
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
2.06k
                for (int pl = 0; pl < 2; pl++) {
1745
1.37k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.37k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.37k
                    enum IntraPredMode m =
1748
1.37k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.15k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.37k
                    int angle = 0;
1751
1.37k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.37k
                    const pixel *top_sb_edge = NULL;
1753
1.37k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.33k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.33k
                        const int sby = t->by >> f->sb_shift;
1756
1.33k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.33k
                    }
1758
1.37k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.37k
                                                          (t->bx >> ss_hor) >
1760
1.37k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.37k
                                                          t->by >> ss_ver,
1762
1.37k
                                                          (t->by >> ss_ver) >
1763
1.37k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.37k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.37k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.37k
                                                          0, uvdst, f->cur.stride[1],
1767
1.37k
                                                          top_sb_edge, m,
1768
1.37k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.37k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.37k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.37k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.37k
                                             HIGHBD_CALL_SUFFIX);
1773
1.37k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.37k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.37k
                }
1776
689
            }
1777
18.5k
        }
1778
1779
23.7k
    skip_inter_chroma_pred: {}
1780
23.7k
        t->tl_4x4_filter = filter_2d;
1781
23.7k
    } else {
1782
5.19k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
5.19k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
5.19k
        int jnt_weight;
1786
5.19k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
5.19k
        const uint8_t *mask;
1788
1789
15.5k
        for (int i = 0; i < 2; i++) {
1790
10.3k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
10.3k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
960
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
960
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
960
                if (res) return res;
1796
9.43k
            } else {
1797
9.43k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
9.43k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
9.43k
                if (res) return res;
1800
9.43k
            }
1801
10.3k
        }
1802
5.19k
        switch (b->comp_type) {
1803
4.22k
        case COMP_INTER_AVG:
1804
4.22k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
4.22k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
4.22k
            break;
1807
504
        case COMP_INTER_WEIGHTED_AVG:
1808
504
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
504
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
504
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
504
            break;
1812
281
        case COMP_INTER_SEG:
1813
281
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
281
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
281
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
281
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
281
            mask = seg_mask;
1818
281
            break;
1819
188
        case COMP_INTER_WEDGE:
1820
188
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
188
            dsp->mc.mask(dst, f->cur.stride[0],
1822
188
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
188
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
188
            if (has_chroma)
1825
186
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
188
            break;
1827
5.19k
        }
1828
1829
        // chroma
1830
13.8k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
27.6k
            for (int i = 0; i < 2; i++) {
1832
18.4k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
18.4k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
4.32k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.83k
                {
1836
1.83k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.83k
                                      b_dim, 1 + pl,
1838
1.83k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.83k
                    if (res) return res;
1840
16.6k
                } else {
1841
16.6k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
16.6k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
16.6k
                    if (res) return res;
1844
16.6k
                }
1845
18.4k
            }
1846
9.22k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
9.22k
            switch (b->comp_type) {
1848
7.91k
            case COMP_INTER_AVG:
1849
7.91k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
7.91k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
7.91k
                            HIGHBD_CALL_SUFFIX);
1852
7.91k
                break;
1853
402
            case COMP_INTER_WEIGHTED_AVG:
1854
402
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
402
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
402
                              HIGHBD_CALL_SUFFIX);
1857
402
                break;
1858
372
            case COMP_INTER_WEDGE:
1859
910
            case COMP_INTER_SEG:
1860
910
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
910
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
910
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
910
                             HIGHBD_CALL_SUFFIX);
1864
910
                break;
1865
9.22k
            }
1866
9.22k
        }
1867
5.19k
    }
1868
1869
47.1k
    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
47.1k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
47.1k
    if (b->skip) {
1882
        // reset coef contexts
1883
14.6k
        BlockContext *const a = t->a;
1884
14.6k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
14.6k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
14.6k
        if (has_chroma) {
1887
12.9k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
12.9k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
12.9k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
12.9k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
12.9k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
12.9k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
12.9k
        }
1894
14.6k
        return 0;
1895
14.6k
    }
1896
1897
32.5k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
32.5k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
32.5k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
69.3k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
74.0k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
37.2k
            int y_off = !!init_y, y;
1905
37.2k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
74.8k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
37.6k
                 y += ytx->h, y_off++)
1908
37.6k
            {
1909
37.6k
                int x, x_off = !!init_x;
1910
77.5k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
39.8k
                     x += ytx->w, x_off++)
1912
39.8k
                {
1913
39.8k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
39.8k
                                   x_off, y_off, &dst[x * 4]);
1915
39.8k
                    t->bx += ytx->w;
1916
39.8k
                }
1917
37.6k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
37.6k
                t->bx -= x;
1919
37.6k
                t->by += ytx->h;
1920
37.6k
            }
1921
37.2k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
37.2k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
90.1k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
60.1k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
60.1k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
60.1k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
126k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
66.4k
                {
1931
66.4k
                    int x;
1932
66.4k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
138k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
72.0k
                    {
1935
72.0k
                        coef *cf;
1936
72.0k
                        int eob;
1937
72.0k
                        enum TxfmType txtp;
1938
72.0k
                        if (t->frame_thread.pass) {
1939
72.0k
                            const int p = t->frame_thread.pass & 1;
1940
72.0k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
72.0k
                            cf = ts->frame_thread[p].cf;
1942
72.0k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
72.0k
                            eob  = cbi >> 5;
1944
72.0k
                            txtp = cbi & 0x1f;
1945
72.0k
                        } 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
72.0k
                        if (eob >= 0) {
1964
16.4k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
16.4k
                            dsp->itx.itxfm_add[b->uvtx]
1967
16.4k
                                              [txtp](&uvdst[4 * x],
1968
16.4k
                                                     f->cur.stride[1],
1969
16.4k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
16.4k
                            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
16.4k
                        }
1974
72.0k
                        t->bx += uvtx->w << ss_hor;
1975
72.0k
                    }
1976
66.4k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
66.4k
                    t->bx -= x << ss_hor;
1978
66.4k
                    t->by += uvtx->h << ss_ver;
1979
66.4k
                }
1980
60.1k
                t->by -= y << ss_ver;
1981
60.1k
            }
1982
37.2k
        }
1983
36.8k
    }
1984
32.5k
    return 0;
1985
47.1k
}
1986
1987
74.8k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
74.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
74.8k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
74.8k
    const int y = sby * f->sb_step * 4;
1994
74.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
74.8k
    pixel *const p[3] = {
1996
74.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
74.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
74.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
74.8k
    };
2000
74.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
74.8k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
74.8k
                                        f->lf.start_of_tile_row[sby]);
2003
74.8k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
45.4k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
45.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
45.4k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
45.4k
    const int y = sby * f->sb_step * 4;
1994
45.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
45.4k
    pixel *const p[3] = {
1996
45.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
45.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
45.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
45.4k
    };
2000
45.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
45.4k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
45.4k
                                        f->lf.start_of_tile_row[sby]);
2003
45.4k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
29.3k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
29.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
29.3k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
29.3k
    const int y = sby * f->sb_step * 4;
1994
29.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
29.3k
    pixel *const p[3] = {
1996
29.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
29.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
29.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
29.3k
    };
2000
29.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
29.3k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
29.3k
                                        f->lf.start_of_tile_row[sby]);
2003
29.3k
}
2004
2005
77.6k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
77.6k
    const int y = sby * f->sb_step * 4;
2007
77.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
77.6k
    pixel *const p[3] = {
2009
77.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
77.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
77.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
77.6k
    };
2013
77.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
77.6k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
77.6k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
74.7k
    {
2017
74.7k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
74.7k
    }
2019
77.6k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
68.9k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
68.9k
    }
2023
77.6k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
47.6k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
47.6k
    const int y = sby * f->sb_step * 4;
2007
47.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
47.6k
    pixel *const p[3] = {
2009
47.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
47.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
47.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
47.6k
    };
2013
47.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
47.6k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
47.6k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
45.3k
    {
2017
45.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
45.3k
    }
2019
47.6k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
44.3k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
44.3k
    }
2023
47.6k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
30.0k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
30.0k
    const int y = sby * f->sb_step * 4;
2007
30.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
30.0k
    pixel *const p[3] = {
2009
30.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
30.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
30.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
30.0k
    };
2013
30.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
30.0k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
30.0k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
29.3k
    {
2017
29.3k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
29.3k
    }
2019
30.0k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
24.6k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
24.6k
    }
2023
30.0k
}
2024
2025
40.5k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
40.5k
    const Dav1dFrameContext *const f = tc->f;
2027
40.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
40.5k
    const int sbsz = f->sb_step;
2029
40.5k
    const int y = sby * sbsz * 4;
2030
40.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
40.5k
    pixel *const p[3] = {
2032
40.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
40.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
40.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
40.5k
    };
2036
40.5k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
40.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
40.5k
    const int start = sby * sbsz;
2039
40.5k
    if (sby) {
2040
12.0k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
12.0k
        pixel *p_up[3] = {
2042
12.0k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
12.0k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
12.0k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
12.0k
        };
2046
12.0k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
12.0k
    }
2048
40.5k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
40.5k
    const int end = imin(start + n_blks, f->bh);
2050
40.5k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
40.5k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
28.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
28.7k
    const Dav1dFrameContext *const f = tc->f;
2027
28.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
28.7k
    const int sbsz = f->sb_step;
2029
28.7k
    const int y = sby * sbsz * 4;
2030
28.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
28.7k
    pixel *const p[3] = {
2032
28.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
28.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
28.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
28.7k
    };
2036
28.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
28.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
28.7k
    const int start = sby * sbsz;
2039
28.7k
    if (sby) {
2040
6.93k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
6.93k
        pixel *p_up[3] = {
2042
6.93k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
6.93k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
6.93k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
6.93k
        };
2046
6.93k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
6.93k
    }
2048
28.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
28.7k
    const int end = imin(start + n_blks, f->bh);
2050
28.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
28.7k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
11.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
11.7k
    const Dav1dFrameContext *const f = tc->f;
2027
11.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
11.7k
    const int sbsz = f->sb_step;
2029
11.7k
    const int y = sby * sbsz * 4;
2030
11.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
11.7k
    pixel *const p[3] = {
2032
11.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
11.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
11.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
11.7k
    };
2036
11.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
11.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
11.7k
    const int start = sby * sbsz;
2039
11.7k
    if (sby) {
2040
5.07k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
5.07k
        pixel *p_up[3] = {
2042
5.07k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
5.07k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
5.07k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
5.07k
        };
2046
5.07k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
5.07k
    }
2048
11.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
11.7k
    const int end = imin(start + n_blks, f->bh);
2050
11.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
11.7k
}
2052
2053
5.47k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
5.47k
    const int sbsz = f->sb_step;
2055
5.47k
    const int y = sby * sbsz * 4;
2056
5.47k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
5.47k
    const pixel *const p[3] = {
2058
5.47k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
5.47k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
5.47k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
5.47k
    };
2062
5.47k
    pixel *const sr_p[3] = {
2063
5.47k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
5.47k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
5.47k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
5.47k
    };
2067
5.47k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
15.6k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
10.2k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
10.2k
        const int h_start = 8 * !!sby >> ss_ver;
2071
10.2k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
10.2k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
10.2k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
10.2k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
10.2k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
10.2k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
10.2k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
10.2k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
10.2k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
10.2k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
10.2k
                          imin(img_h, h_end) + h_start, src_w,
2083
10.2k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
10.2k
                          HIGHBD_CALL_SUFFIX);
2085
10.2k
    }
2086
5.47k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
2.56k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
2.56k
    const int sbsz = f->sb_step;
2055
2.56k
    const int y = sby * sbsz * 4;
2056
2.56k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
2.56k
    const pixel *const p[3] = {
2058
2.56k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
2.56k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
2.56k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
2.56k
    };
2062
2.56k
    pixel *const sr_p[3] = {
2063
2.56k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
2.56k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
2.56k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
2.56k
    };
2067
2.56k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
7.79k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
5.23k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
5.23k
        const int h_start = 8 * !!sby >> ss_ver;
2071
5.23k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
5.23k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
5.23k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
5.23k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
5.23k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
5.23k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
5.23k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
5.23k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
5.23k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
5.23k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
5.23k
                          imin(img_h, h_end) + h_start, src_w,
2083
5.23k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
5.23k
                          HIGHBD_CALL_SUFFIX);
2085
5.23k
    }
2086
2.56k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
2.91k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
2.91k
    const int sbsz = f->sb_step;
2055
2.91k
    const int y = sby * sbsz * 4;
2056
2.91k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
2.91k
    const pixel *const p[3] = {
2058
2.91k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
2.91k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
2.91k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
2.91k
    };
2062
2.91k
    pixel *const sr_p[3] = {
2063
2.91k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
2.91k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
2.91k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
2.91k
    };
2067
2.91k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
7.88k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
4.96k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
4.96k
        const int h_start = 8 * !!sby >> ss_ver;
2071
4.96k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
4.96k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
4.96k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
4.96k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
4.96k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
4.96k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
4.96k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
4.96k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
4.96k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
4.96k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
4.96k
                          imin(img_h, h_end) + h_start, src_w,
2083
4.96k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
4.96k
                          HIGHBD_CALL_SUFFIX);
2085
4.96k
    }
2086
2.91k
}
2087
2088
54.3k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
54.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
54.3k
    const int y = sby * f->sb_step * 4;
2091
54.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
54.3k
    pixel *const sr_p[3] = {
2093
54.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
54.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
54.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
54.3k
    };
2097
54.3k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
54.3k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
33.7k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
33.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
33.7k
    const int y = sby * f->sb_step * 4;
2091
33.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
33.7k
    pixel *const sr_p[3] = {
2093
33.7k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
33.7k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
33.7k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
33.7k
    };
2097
33.7k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
33.7k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
20.5k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
20.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
20.5k
    const int y = sby * f->sb_step * 4;
2091
20.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
20.5k
    pixel *const sr_p[3] = {
2093
20.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
20.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
20.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
20.5k
    };
2097
20.5k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
20.5k
}
2099
2100
0
void bytefn(dav1d_filter_sbrow)(Dav1dFrameContext *const f, const int sby) {
2101
0
    bytefn(dav1d_filter_sbrow_deblock_cols)(f, sby);
2102
0
    bytefn(dav1d_filter_sbrow_deblock_rows)(f, sby);
2103
0
    if (f->seq_hdr->cdef)
2104
0
        bytefn(dav1d_filter_sbrow_cdef)(f->c->tc, sby);
2105
0
    if (f->frame_hdr->width[0] != f->frame_hdr->width[1])
2106
0
        bytefn(dav1d_filter_sbrow_resize)(f, sby);
2107
0
    if (f->lf.restore_planes)
2108
0
        bytefn(dav1d_filter_sbrow_lr)(f, sby);
2109
0
}
Unexecuted instantiation: dav1d_filter_sbrow_8bpc
Unexecuted instantiation: dav1d_filter_sbrow_16bpc
2110
2111
84.2k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
84.2k
    const Dav1dFrameContext *const f = t->f;
2113
84.2k
    Dav1dTileState *const ts = t->ts;
2114
84.2k
    const int sby = t->by >> f->sb_shift;
2115
84.2k
    const int sby_off = f->sb128w * 128 * sby;
2116
84.2k
    const int x_off = ts->tiling.col_start;
2117
2118
84.2k
    const pixel *const y =
2119
84.2k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
84.2k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
84.2k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
84.2k
               4 * (ts->tiling.col_end - x_off));
2123
2124
84.2k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
70.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
70.7k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
70.7k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
70.7k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
212k
        for (int pl = 1; pl <= 2; pl++)
2131
141k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
87.2k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
87.2k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
70.7k
    }
2135
84.2k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
49.8k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
49.8k
    const Dav1dFrameContext *const f = t->f;
2113
49.8k
    Dav1dTileState *const ts = t->ts;
2114
49.8k
    const int sby = t->by >> f->sb_shift;
2115
49.8k
    const int sby_off = f->sb128w * 128 * sby;
2116
49.8k
    const int x_off = ts->tiling.col_start;
2117
2118
49.8k
    const pixel *const y =
2119
49.8k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
49.8k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
49.8k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
49.8k
               4 * (ts->tiling.col_end - x_off));
2123
2124
49.8k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
43.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
43.6k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
43.6k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
43.6k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
130k
        for (int pl = 1; pl <= 2; pl++)
2131
87.2k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
87.2k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
87.2k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
43.6k
    }
2135
49.8k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
34.4k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
34.4k
    const Dav1dFrameContext *const f = t->f;
2113
34.4k
    Dav1dTileState *const ts = t->ts;
2114
34.4k
    const int sby = t->by >> f->sb_shift;
2115
34.4k
    const int sby_off = f->sb128w * 128 * sby;
2116
34.4k
    const int x_off = ts->tiling.col_start;
2117
2118
34.4k
    const pixel *const y =
2119
34.4k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
34.4k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
34.4k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
34.4k
               4 * (ts->tiling.col_end - x_off));
2123
2124
34.4k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
27.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
27.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
27.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
27.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
81.4k
        for (int pl = 1; pl <= 2; pl++)
2131
54.3k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
27.1k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
27.1k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
27.1k
    }
2135
34.4k
}
2136
2137
void bytefn(dav1d_copy_pal_block_y)(Dav1dTaskContext *const t,
2138
                                    const int bx4, const int by4,
2139
                                    const int bw4, const int bh4)
2140
2141
11.7k
{
2142
11.7k
    const Dav1dFrameContext *const f = t->f;
2143
11.7k
    pixel *const pal = t->frame_thread.pass ?
2144
11.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
11.7k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
11.7k
        bytefn(t->scratch.pal)[0];
2147
53.4k
    for (int x = 0; x < bw4; x++)
2148
41.6k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
46.8k
    for (int y = 0; y < bh4; y++)
2150
35.0k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
11.7k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
6.56k
{
2142
6.56k
    const Dav1dFrameContext *const f = t->f;
2143
6.56k
    pixel *const pal = t->frame_thread.pass ?
2144
6.56k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
6.56k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
6.56k
        bytefn(t->scratch.pal)[0];
2147
29.4k
    for (int x = 0; x < bw4; x++)
2148
22.8k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
25.2k
    for (int y = 0; y < bh4; y++)
2150
18.7k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
6.56k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
5.15k
{
2142
5.15k
    const Dav1dFrameContext *const f = t->f;
2143
5.15k
    pixel *const pal = t->frame_thread.pass ?
2144
5.15k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
5.15k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
5.15k
        bytefn(t->scratch.pal)[0];
2147
23.9k
    for (int x = 0; x < bw4; x++)
2148
18.8k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
21.5k
    for (int y = 0; y < bh4; y++)
2150
16.3k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
5.15k
}
2152
2153
void bytefn(dav1d_copy_pal_block_uv)(Dav1dTaskContext *const t,
2154
                                     const int bx4, const int by4,
2155
                                     const int bw4, const int bh4)
2156
2157
5.23k
{
2158
5.23k
    const Dav1dFrameContext *const f = t->f;
2159
5.23k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
5.23k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
5.23k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
5.23k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
15.7k
    for (int pl = 1; pl <= 2; pl++) {
2165
56.0k
        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
52.6k
        for (int y = 0; y < bh4; y++)
2168
42.1k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
10.4k
    }
2170
5.23k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
3.27k
{
2158
3.27k
    const Dav1dFrameContext *const f = t->f;
2159
3.27k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
3.27k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
3.27k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
3.27k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
9.83k
    for (int pl = 1; pl <= 2; pl++) {
2165
35.8k
        for (int x = 0; x < bw4; x++)
2166
29.2k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
32.7k
        for (int y = 0; y < bh4; y++)
2168
26.1k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
6.55k
    }
2170
3.27k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
1.96k
{
2158
1.96k
    const Dav1dFrameContext *const f = t->f;
2159
1.96k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
1.96k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
1.96k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
1.96k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
5.88k
    for (int pl = 1; pl <= 2; pl++) {
2165
20.2k
        for (int x = 0; x < bw4; x++)
2166
16.3k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
19.8k
        for (int y = 0; y < bh4; y++)
2168
15.9k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
3.92k
    }
2170
1.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
16.9k
{
2176
16.9k
    Dav1dTileState *const ts = t->ts;
2177
16.9k
    const Dav1dFrameContext *const f = t->f;
2178
16.9k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
16.9k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
16.9k
    pixel cache[16], used_cache[8];
2181
16.9k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
16.9k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
16.9k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
16.9k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
16.9k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
28.7k
    while (l_cache && a_cache) {
2190
11.7k
        if (*l < *a) {
2191
4.67k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
4.65k
                cache[n_cache++] = *l;
2193
4.67k
            l++;
2194
4.67k
            l_cache--;
2195
7.11k
        } else {
2196
7.11k
            if (*a == *l) {
2197
2.77k
                l++;
2198
2.77k
                l_cache--;
2199
2.77k
            }
2200
7.11k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
6.90k
                cache[n_cache++] = *a;
2202
7.11k
            a++;
2203
7.11k
            a_cache--;
2204
7.11k
        }
2205
11.7k
    }
2206
16.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
12.2k
    } else if (a_cache) {
2213
14.5k
        do {
2214
14.5k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
11.6k
                cache[n_cache++] = *a;
2216
14.5k
            a++;
2217
14.5k
        } while (--a_cache > 0);
2218
3.64k
    }
2219
2220
    // find reused cache entries
2221
16.9k
    int i = 0;
2222
51.1k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
34.2k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
16.7k
            used_cache[i++] = cache[n];
2225
16.9k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
16.9k
    pixel *const pal = t->frame_thread.pass ?
2229
16.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
16.9k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
16.9k
        bytefn(t->scratch.pal)[pl];
2232
16.9k
    if (i < pal_sz) {
2233
14.7k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
14.7k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
14.7k
        if (i < pal_sz) {
2237
13.3k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
13.3k
            const int max = (1 << bpc) - 1;
2239
2240
31.4k
            do {
2241
31.4k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
31.4k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
31.4k
                if (prev + !pl >= max) {
2244
16.7k
                    for (; i < pal_sz; i++)
2245
10.8k
                        pal[i] = max;
2246
5.90k
                    break;
2247
5.90k
                }
2248
25.5k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
25.5k
            } while (i < pal_sz);
2250
13.3k
        }
2251
2252
        // merge cache+new entries
2253
14.7k
        int n = 0, m = n_used_cache;
2254
82.7k
        for (i = 0; i < pal_sz; i++) {
2255
67.9k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
10.9k
                pal[i] = used_cache[n++];
2257
57.0k
            } else {
2258
57.0k
                assert(m < pal_sz);
2259
57.0k
                pal[i] = pal[m++];
2260
57.0k
            }
2261
67.9k
        }
2262
14.7k
    } else {
2263
2.15k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
2.15k
    }
2265
2266
16.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
16.9k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
9.83k
{
2176
9.83k
    Dav1dTileState *const ts = t->ts;
2177
9.83k
    const Dav1dFrameContext *const f = t->f;
2178
9.83k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
9.83k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
9.83k
    pixel cache[16], used_cache[8];
2181
9.83k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
9.83k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
9.83k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
9.83k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
9.83k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
18.0k
    while (l_cache && a_cache) {
2190
8.23k
        if (*l < *a) {
2191
3.25k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
3.24k
                cache[n_cache++] = *l;
2193
3.25k
            l++;
2194
3.25k
            l_cache--;
2195
4.97k
        } else {
2196
4.97k
            if (*a == *l) {
2197
1.91k
                l++;
2198
1.91k
                l_cache--;
2199
1.91k
            }
2200
4.97k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
4.82k
                cache[n_cache++] = *a;
2202
4.97k
            a++;
2203
4.97k
            a_cache--;
2204
4.97k
        }
2205
8.23k
    }
2206
9.83k
    if (l_cache) {
2207
11.4k
        do {
2208
11.4k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
9.32k
                cache[n_cache++] = *l;
2210
11.4k
            l++;
2211
11.4k
        } while (--l_cache > 0);
2212
7.01k
    } else if (a_cache) {
2213
8.49k
        do {
2214
8.49k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
6.75k
                cache[n_cache++] = *a;
2216
8.49k
            a++;
2217
8.49k
        } while (--a_cache > 0);
2218
2.17k
    }
2219
2220
    // find reused cache entries
2221
9.83k
    int i = 0;
2222
31.0k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
21.1k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
10.3k
            used_cache[i++] = cache[n];
2225
9.83k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
9.83k
    pixel *const pal = t->frame_thread.pass ?
2229
9.83k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
9.83k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
9.83k
        bytefn(t->scratch.pal)[pl];
2232
9.83k
    if (i < pal_sz) {
2233
8.51k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
8.51k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
8.51k
        if (i < pal_sz) {
2237
7.62k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
7.62k
            const int max = (1 << bpc) - 1;
2239
2240
17.9k
            do {
2241
17.9k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
17.9k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
17.9k
                if (prev + !pl >= max) {
2244
9.66k
                    for (; i < pal_sz; i++)
2245
6.26k
                        pal[i] = max;
2246
3.39k
                    break;
2247
3.39k
                }
2248
14.5k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
14.5k
            } while (i < pal_sz);
2250
7.62k
        }
2251
2252
        // merge cache+new entries
2253
8.51k
        int n = 0, m = n_used_cache;
2254
48.0k
        for (i = 0; i < pal_sz; i++) {
2255
39.4k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
6.72k
                pal[i] = used_cache[n++];
2257
32.7k
            } else {
2258
32.7k
                assert(m < pal_sz);
2259
32.7k
                pal[i] = pal[m++];
2260
32.7k
            }
2261
39.4k
        }
2262
8.51k
    } else {
2263
1.32k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.32k
    }
2265
2266
9.83k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
9.83k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
7.11k
{
2176
7.11k
    Dav1dTileState *const ts = t->ts;
2177
7.11k
    const Dav1dFrameContext *const f = t->f;
2178
7.11k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
7.11k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
7.11k
    pixel cache[16], used_cache[8];
2181
7.11k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
7.11k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
7.11k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
7.11k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
7.11k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
10.6k
    while (l_cache && a_cache) {
2190
3.55k
        if (*l < *a) {
2191
1.41k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
1.41k
                cache[n_cache++] = *l;
2193
1.41k
            l++;
2194
1.41k
            l_cache--;
2195
2.13k
        } else {
2196
2.13k
            if (*a == *l) {
2197
855
                l++;
2198
855
                l_cache--;
2199
855
            }
2200
2.13k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
2.08k
                cache[n_cache++] = *a;
2202
2.13k
            a++;
2203
2.13k
            a_cache--;
2204
2.13k
        }
2205
3.55k
    }
2206
7.11k
    if (l_cache) {
2207
7.77k
        do {
2208
7.77k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
6.22k
                cache[n_cache++] = *l;
2210
7.77k
            l++;
2211
7.77k
        } while (--l_cache > 0);
2212
5.24k
    } else if (a_cache) {
2213
6.01k
        do {
2214
6.01k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
4.91k
                cache[n_cache++] = *a;
2216
6.01k
            a++;
2217
6.01k
        } while (--a_cache > 0);
2218
1.46k
    }
2219
2220
    // find reused cache entries
2221
7.11k
    int i = 0;
2222
20.1k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
13.0k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
6.37k
            used_cache[i++] = cache[n];
2225
7.11k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
7.11k
    pixel *const pal = t->frame_thread.pass ?
2229
7.11k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
7.11k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
7.11k
        bytefn(t->scratch.pal)[pl];
2232
7.11k
    if (i < pal_sz) {
2233
6.27k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
6.27k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
6.27k
        if (i < pal_sz) {
2237
5.74k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
5.74k
            const int max = (1 << bpc) - 1;
2239
2240
13.4k
            do {
2241
13.4k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
13.4k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
13.4k
                if (prev + !pl >= max) {
2244
7.05k
                    for (; i < pal_sz; i++)
2245
4.55k
                        pal[i] = max;
2246
2.50k
                    break;
2247
2.50k
                }
2248
10.9k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
10.9k
            } while (i < pal_sz);
2250
5.74k
        }
2251
2252
        // merge cache+new entries
2253
6.27k
        int n = 0, m = n_used_cache;
2254
34.7k
        for (i = 0; i < pal_sz; i++) {
2255
28.4k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
4.17k
                pal[i] = used_cache[n++];
2257
24.2k
            } else {
2258
24.2k
                assert(m < pal_sz);
2259
24.2k
                pal[i] = pal[m++];
2260
24.2k
            }
2261
28.4k
        }
2262
6.27k
    } else {
2263
838
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
838
    }
2265
2266
7.11k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
7.11k
}
2277
2278
void bytefn(dav1d_read_pal_uv)(Dav1dTaskContext *const t, Av1Block *const b,
2279
                               const int sz_ctx, const int bx4, const int by4)
2280
5.23k
{
2281
5.23k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
5.23k
    Dav1dTileState *const ts = t->ts;
2285
5.23k
    const Dav1dFrameContext *const f = t->f;
2286
5.23k
    pixel *const pal = t->frame_thread.pass ?
2287
5.23k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
5.23k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
5.23k
        bytefn(t->scratch.pal)[2];
2290
5.23k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
5.23k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.62k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.62k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.62k
        const int max = (1 << bpc) - 1;
2295
10.8k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
8.21k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
8.21k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
8.21k
            prev = pal[i] = (prev + delta) & max;
2299
8.21k
        }
2300
2.62k
    } 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
5.23k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
5.23k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
3.27k
{
2281
3.27k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
3.27k
    Dav1dTileState *const ts = t->ts;
2285
3.27k
    const Dav1dFrameContext *const f = t->f;
2286
3.27k
    pixel *const pal = t->frame_thread.pass ?
2287
3.27k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
3.27k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
3.27k
        bytefn(t->scratch.pal)[2];
2290
3.27k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
3.27k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.64k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.64k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.64k
        const int max = (1 << bpc) - 1;
2295
6.89k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
5.24k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
5.24k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
5.24k
            prev = pal[i] = (prev + delta) & max;
2299
5.24k
        }
2300
1.64k
    } else {
2301
8.45k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
6.82k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.63k
    }
2304
3.27k
    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.27k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
1.96k
{
2281
1.96k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
1.96k
    Dav1dTileState *const ts = t->ts;
2285
1.96k
    const Dav1dFrameContext *const f = t->f;
2286
1.96k
    pixel *const pal = t->frame_thread.pass ?
2287
1.96k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
1.96k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
1.96k
        bytefn(t->scratch.pal)[2];
2290
1.96k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
1.96k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
980
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
980
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
980
        const int max = (1 << bpc) - 1;
2295
3.94k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
2.96k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
2.96k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
2.96k
            prev = pal[i] = (prev + delta) & max;
2299
2.96k
        }
2300
981
    } else {
2301
4.91k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
3.93k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
981
    }
2304
1.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
1.96k
}