Coverage Report

Created: 2026-05-30 06:08

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