Coverage Report

Created: 2026-09-01 06:54

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