Coverage Report

Created: 2026-10-17 06:56

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
856k
static inline unsigned read_golomb(MsacContext *const msac) {
50
856k
    int len = 0;
51
856k
    unsigned val = 1;
52
53
1.62M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
1.62M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
856k
    return val - 1;
57
856k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
4.89M
{
66
4.89M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
4.89M
    if (chroma) {
69
2.87M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
2.87M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
2.87M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.67M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
2.87M
        unsigned ca, cl;
74
75
2.87M
#define MERGE_CTX(dir, type, no_val) \
76
5.75M
        c##dir = *(const type *) dir != no_val; \
77
5.75M
        break
78
79
2.87M
        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
1.22M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
528k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
436k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
686k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
2.87M
        }
91
2.87M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
1.33M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
571k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
332k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
639k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
2.87M
        }
98
2.87M
#undef MERGE_CTX
99
100
2.87M
        return 7 + not_one_blk * 3 + ca + cl;
101
2.87M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
871k
        return 0;
103
1.15M
    } else {
104
1.15M
        unsigned la, ll;
105
106
1.15M
#define MERGE_CTX(dir, type, tx) \
107
2.37M
        if (tx == TX_64X64) { \
108
182k
            uint64_t tmp = *(const uint64_t *) dir; \
109
182k
            tmp |= *(const uint64_t *) &dir[8]; \
110
182k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
182k
        } else \
112
2.37M
            l##dir = *(const type *) dir; \
113
2.37M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
2.37M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
2.37M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
2.37M
        break
117
118
1.15M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
641k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
247k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
187k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
19.8k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
91.4k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.15M
        }
126
1.18M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
649k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
241k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
186k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
19.9k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
91.4k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.18M
        }
134
1.18M
#undef MERGE_CTX
135
136
1.18M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.18M
    }
138
4.89M
}
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.97M
{
144
1.97M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
1.97M
    int s;
146
147
1.97M
#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.97M
    __asm__("" : "+r"(mask), "+r"(mul));
151
1.97M
#endif
152
153
1.97M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
814k
    case TX_4X4: {
156
814k
        int t = *(const uint8_t *) a >> 6;
157
814k
        t    += *(const uint8_t *) l >> 6;
158
814k
        s = t - 1 - 1;
159
814k
        break;
160
0
    }
161
220k
    case TX_8X8: {
162
220k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
220k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
220k
        t *= 0x04040404U;
165
220k
        s = (int) (t >> 24) - 2 - 2;
166
220k
        break;
167
0
    }
168
152k
    case TX_16X16: {
169
152k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
152k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
152k
        t *= (uint32_t) mul;
172
152k
        s = (int) (t >> 24) - 4 - 4;
173
152k
        break;
174
0
    }
175
147k
    case TX_32X32: {
176
147k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
147k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
147k
        t *= mul;
179
147k
        s = (int) (t >> 56) - 8 - 8;
180
147k
        break;
181
0
    }
182
60.8k
    case TX_64X64: {
183
60.8k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
60.8k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
60.8k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
60.8k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
60.8k
        t *= mul;
188
60.8k
        s = (int) (t >> 56) - 16 - 16;
189
60.8k
        break;
190
0
    }
191
65.9k
    case RTX_4X8: {
192
65.9k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
65.9k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
65.9k
        t *= 0x04040404U;
195
65.9k
        s = (int) (t >> 24) - 1 - 2;
196
65.9k
        break;
197
0
    }
198
94.7k
    case RTX_8X4: {
199
94.7k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
94.7k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
94.7k
        t *= 0x04040404U;
202
94.7k
        s = (int) (t >> 24) - 2 - 1;
203
94.7k
        break;
204
0
    }
205
60.3k
    case RTX_8X16: {
206
60.3k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
60.3k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
60.3k
        t = (t >> 6) * (uint32_t) mul;
209
60.3k
        s = (int) (t >> 24) - 2 - 4;
210
60.3k
        break;
211
0
    }
212
106k
    case RTX_16X8: {
213
106k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
106k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
106k
        t = (t >> 6) * (uint32_t) mul;
216
106k
        s = (int) (t >> 24) - 4 - 2;
217
106k
        break;
218
0
    }
219
27.0k
    case RTX_16X32: {
220
27.0k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
27.0k
        t         += *(const uint64_t *) l & mask;
222
27.0k
        t = (t >> 6) * mul;
223
27.0k
        s = (int) (t >> 56) - 4 - 8;
224
27.0k
        break;
225
0
    }
226
48.5k
    case RTX_32X16: {
227
48.5k
        uint64_t t = *(const uint64_t *) a & mask;
228
48.5k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
48.5k
        t = (t >> 6) * mul;
230
48.5k
        s = (int) (t >> 56) - 8 - 4;
231
48.5k
        break;
232
0
    }
233
18.6k
    case RTX_32X64: {
234
18.6k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
18.6k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
18.6k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
18.6k
        t *= mul;
238
18.6k
        s = (int) (t >> 56) - 8 - 16;
239
18.6k
        break;
240
0
    }
241
14.9k
    case RTX_64X32: {
242
14.9k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
14.9k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
14.9k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
14.9k
        t *= mul;
246
14.9k
        s = (int) (t >> 56) - 16 - 8;
247
14.9k
        break;
248
0
    }
249
30.1k
    case RTX_4X16: {
250
30.1k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
30.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
30.1k
        t = (t >> 6) * (uint32_t) mul;
253
30.1k
        s = (int) (t >> 24) - 1 - 4;
254
30.1k
        break;
255
0
    }
256
62.3k
    case RTX_16X4: {
257
62.3k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
62.3k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
62.3k
        t = (t >> 6) * (uint32_t) mul;
260
62.3k
        s = (int) (t >> 24) - 4 - 1;
261
62.3k
        break;
262
0
    }
263
17.4k
    case RTX_8X32: {
264
17.4k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
17.4k
        t         += *(const uint64_t *) l & mask;
266
17.4k
        t = (t >> 6) * mul;
267
17.4k
        s = (int) (t >> 56) - 2 - 8;
268
17.4k
        break;
269
0
    }
270
28.5k
    case RTX_32X8: {
271
28.5k
        uint64_t t = *(const uint64_t *) a & mask;
272
28.5k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
28.5k
        t = (t >> 6) * mul;
274
28.5k
        s = (int) (t >> 56) - 8 - 2;
275
28.5k
        break;
276
0
    }
277
6.27k
    case RTX_16X64: {
278
6.27k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
6.27k
        t         += *(const uint64_t *) &l[0] & mask;
280
6.27k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
6.27k
        t *= mul;
282
6.27k
        s = (int) (t >> 56) - 4 - 16;
283
6.27k
        break;
284
0
    }
285
4.17k
    case RTX_64X16: {
286
4.17k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
4.17k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
4.17k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
4.17k
        t *= mul;
290
4.17k
        s = (int) (t >> 56) - 16 - 4;
291
4.17k
        break;
292
0
    }
293
1.97M
    }
294
295
1.98M
    return (s != 0) + (s > 0);
296
1.97M
}
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
34.7M
{
305
34.7M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
34.7M
    unsigned offset;
307
34.7M
    if (tx_class == TX_CLASS_2D) {
308
31.8M
        mag += levels[1 * stride + 1];
309
31.8M
        *hi_mag = mag;
310
31.8M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
31.8M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
31.8M
    } else {
313
2.88M
        mag += levels[0 * stride + 2];
314
2.88M
        *hi_mag = mag;
315
2.88M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
2.88M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
2.88M
    }
318
34.7M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
34.7M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
4.89M
{
328
4.89M
    Dav1dTileState *const ts = t->ts;
329
4.89M
    const int chroma = !!plane;
330
4.89M
    const Dav1dFrameContext *const f = t->f;
331
4.89M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
4.89M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
4.89M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
4.89M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
4.89M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
4.89M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
4.89M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
4.89M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
4.89M
    if (all_skip) {
346
2.52M
        *res_ctx = 0x40;
347
2.52M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
2.52M
        return -1;
349
2.52M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
2.36M
    if (lossless) {
353
764k
        assert(t_dim->max == TX_4X4);
354
764k
        *txtp = WHT_WHT;
355
1.60M
    } else if (t_dim->max + intra >= TX_64X64) {
356
350k
        *txtp = DCT_DCT;
357
1.25M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
355k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
355k
                        get_uv_inter_txtp(t_dim, *txtp);
361
898k
    } 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
6.62k
        *txtp = DCT_DCT;
366
891k
    } else {
367
891k
        unsigned idx;
368
891k
        if (intra) {
369
591k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
505k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
591k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
272k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
272k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
272k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
319k
            } else {
376
319k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
319k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
319k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
319k
            }
380
591k
            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
591k
        } else {
384
299k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
71.6k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
71.6k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
71.6k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
228k
            } else if (t_dim->min == TX_16X16) {
389
26.2k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
26.2k
                          ts->cdf.m.txtp_inter2, 11);
391
26.2k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
201k
            } else {
393
201k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
201k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
201k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
201k
            }
397
299k
            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
299k
        }
401
891k
    }
402
403
    // find end-of-block (eob)
404
2.36M
    int eob;
405
2.36M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
2.36M
    const int tx2dszctx = slw + slh;
407
2.36M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
2.36M
    const int is_1d = tx_class != TX_CLASS_2D;
409
2.36M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
2.40M
    case sz: { \
412
2.40M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
2.40M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
2.40M
        break; \
415
2.40M
    }
416
954k
    case_sz(0,   16,  8, [is_1d]);
417
214k
    case_sz(1,   32,  8, [is_1d]);
418
411k
    case_sz(2,   64,  8, [is_1d]);
419
221k
    case_sz(3,  128,  8, [is_1d]);
420
246k
    case_sz(4,  256, 16, [is_1d]);
421
99.0k
    case_sz(5,  512, 16,        );
422
261k
    case_sz(6, 1024, 16,        );
423
2.36M
#undef case_sz
424
2.36M
    }
425
2.39M
    if (dbg)
426
0
        printf("Post-eob_bin_%d[%d][%d][%d]: r=%d\n",
427
0
               16 << tx2dszctx, chroma, is_1d, eob, ts->msac.rng);
428
2.39M
    if (eob > 1) {
429
1.44M
        const int eob_bin = eob - 2;
430
1.44M
        uint16_t *const eob_hi_bit_cdf =
431
1.44M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.44M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.44M
        if (dbg)
434
0
            printf("Post-eob_hi_bit[%d][%d][%d][%d]: r=%d\n",
435
0
                   t_dim->ctx, chroma, eob_bin, eob_hi_bit, ts->msac.rng);
436
1.44M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.44M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.44M
    }
440
2.39M
    assert(eob >= 0);
441
442
    // base tokens
443
2.39M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
2.39M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
2.39M
    unsigned rc, dc_tok;
446
447
2.39M
    if (eob) {
448
1.52M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.52M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.52M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.52M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.52M
        int tok = eob_tok + 1;
455
1.52M
        int level_tok = tok * 0x41;
456
1.52M
        unsigned mag;
457
458
1.52M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.52M
        unsigned x, y; \
460
1.52M
        uint8_t *level; \
461
1.52M
        if (tx_class == TX_CLASS_2D) \
462
1.52M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.52M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
155k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
155k
        else /* tx_class == TX_CLASS_V */ \
467
155k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.52M
        if (dbg) \
469
1.52M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
1.52M
        if (eob_tok == 2) { \
472
30.2k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
30.2k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
30.2k
            level_tok = tok + (3 << 6); \
475
30.2k
            if (dbg) \
476
30.2k
                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
30.2k
        } \
480
1.52M
        cf[rc] = tok << 11; \
481
1.52M
        if (tx_class == TX_CLASS_2D) \
482
1.52M
            level = levels + rc; \
483
1.52M
        else \
484
1.52M
            level = levels + x * stride + y; \
485
1.52M
        *level = (uint8_t) level_tok; \
486
36.1M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
34.6M
            unsigned rc_i; \
488
34.6M
            if (tx_class == TX_CLASS_2D) \
489
34.6M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
34.6M
            else if (tx_class == TX_CLASS_H) \
491
2.78M
                x = i & mask, y = i >> shift, rc_i = i; \
492
2.78M
            else /* tx_class == TX_CLASS_V */ \
493
2.78M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
34.6M
            assert(x < 32 && y < 32); \
495
34.6M
            if (tx_class == TX_CLASS_2D) \
496
34.6M
                level = levels + rc_i; \
497
34.6M
            else \
498
34.6M
                level = levels + x * stride + y; \
499
34.6M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
34.6M
            if (tx_class == TX_CLASS_2D) \
501
34.6M
                y |= x; \
502
34.6M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
34.6M
            if (dbg) \
504
34.6M
                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
34.6M
            if (tok == 3) { \
507
3.00M
                mag &= 63; \
508
3.00M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
3.00M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
3.00M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
3.00M
                if (dbg) \
512
3.00M
                    printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
513
0
                           imin(t_dim->ctx, 3), chroma, ctx, i, rc_i, tok, \
514
0
                           ts->msac.rng); \
515
3.00M
                *level = (uint8_t) (tok + (3 << 6)); \
516
3.00M
                cf[rc_i] = (tok << 11) | rc; \
517
3.00M
                rc = rc_i; \
518
31.6M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
31.6M
                tok *= 0x17ff41; \
521
31.6M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
31.6M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
31.6M
                if (tok) rc = rc_i; \
525
31.6M
                cf[rc_i] = tok; \
526
31.6M
            } \
527
34.6M
        } \
528
        /* dc */ \
529
1.52M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.52M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.52M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.52M
        if (dbg) \
533
1.52M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
1.52M
        if (dc_tok == 3) { \
536
516k
            if (tx_class == TX_CLASS_2D) \
537
516k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
504k
                      levels[1 * stride + 1]; \
539
516k
            mag &= 63; \
540
516k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
516k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
516k
            if (dbg) \
543
516k
                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
516k
        } \
546
1.52M
        break
547
548
1.52M
        const uint16_t *scan;
549
1.52M
        switch (tx_class) {
550
1.36M
        case TX_CLASS_2D: {
551
1.36M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.36M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.36M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.36M
            scan = dav1d_scans[tx];
555
1.36M
            const ptrdiff_t stride = 4 << slh;
556
1.36M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.36M
            const unsigned mask = (4 << slh) - 1;
558
1.36M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.36M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.36M
        }
561
103k
        case TX_CLASS_H: {
562
103k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
103k
            const ptrdiff_t stride = 16;
564
103k
            const unsigned shift = slh + 2, shift2 = 0;
565
103k
            const unsigned mask = (4 << slh) - 1;
566
103k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
103k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
103k
        }
569
56.8k
        case TX_CLASS_V: {
570
56.8k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
56.8k
            const ptrdiff_t stride = 16;
572
56.8k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
56.8k
            const unsigned mask = (4 << slw) - 1;
574
56.8k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
56.8k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
56.8k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.52M
        }
580
1.52M
    } else { // dc-only
581
873k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
873k
        dc_tok = 1 + tok_br;
583
873k
        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
873k
        if (tok_br == 2) {
587
33.5k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
33.5k
            if (dbg)
589
0
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n",
590
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng);
591
33.5k
        }
592
873k
        rc = 0;
593
873k
    }
594
595
    // residual and sign
596
2.39M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
2.39M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
2.39M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
2.39M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
2.39M
    unsigned cul_level, dc_sign_level;
601
602
2.39M
    if (!dc_tok) {
603
418k
        cul_level = 0;
604
418k
        dc_sign_level = 1 << 6;
605
418k
        if (qm_tbl) goto ac_qm;
606
289k
        goto ac_noqm;
607
418k
    }
608
609
1.97M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
1.97M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
1.97M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
1.97M
    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.97M
    int dc_dq = dq_tbl[0];
617
1.97M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
1.97M
    if (qm_tbl) {
620
691k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
691k
        if (dc_tok == 15) {
623
16.7k
            dc_tok = read_golomb(&ts->msac) + 15;
624
16.7k
            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
16.7k
            dc_tok &= 0xfffff;
629
16.7k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
674k
        } else {
631
674k
            dc_dq *= dc_tok;
632
674k
            assert(dc_dq <= 0xffffff);
633
674k
        }
634
691k
        cul_level = dc_tok;
635
691k
        dc_dq >>= dq_shift;
636
691k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
691k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
974k
        if (rc) ac_qm: {
640
974k
            const unsigned ac_dq = dq_tbl[1];
641
6.27M
            do {
642
6.27M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
6.27M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
6.27M
                const unsigned rc_tok = cf[rc];
646
6.27M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
6.27M
                int dq_sat;
648
649
6.27M
                if (rc_tok >= (15 << 11)) {
650
606k
                    tok = read_golomb(&ts->msac) + 15;
651
606k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
606k
                    tok &= 0xfffff;
656
606k
                    dq = (dq * tok) & 0xffffff;
657
5.66M
                } else {
658
5.66M
                    tok = rc_tok >> 11;
659
5.66M
                    dq *= tok;
660
5.66M
                    assert(dq <= 0xffffff);
661
5.66M
                }
662
6.27M
                cul_level += tok;
663
6.27M
                dq >>= dq_shift;
664
6.27M
                dq_sat = umin(dq, cf_max + sign);
665
6.27M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
6.27M
                rc = rc_tok & 0x3ff;
668
6.27M
            } while (rc);
669
974k
        }
670
1.28M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
1.28M
        if (dc_tok == 15) {
673
36.1k
            dc_tok = read_golomb(&ts->msac) + 15;
674
36.1k
            if (dbg)
675
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
676
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
677
678
36.1k
            dc_tok &= 0xfffff;
679
36.1k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
36.1k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
1.25M
        } else {
682
1.25M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
1.25M
            assert(dc_dq <= cf_max);
684
1.25M
        }
685
1.28M
        cul_level = dc_tok;
686
1.28M
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
1.66M
        if (rc) ac_noqm: {
689
1.66M
            const unsigned ac_dq = dq_tbl[1];
690
7.46M
            do {
691
7.46M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
7.46M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
7.46M
                const unsigned rc_tok = cf[rc];
695
7.46M
                unsigned tok;
696
7.46M
                int dq;
697
698
                // residual
699
7.46M
                if (rc_tok >= (15 << 11)) {
700
198k
                    tok = read_golomb(&ts->msac) + 15;
701
198k
                    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
198k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
198k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
198k
                    dq = umin(dq, cf_max + sign);
711
7.26M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
7.26M
                    tok = rc_tok >> 11;
714
7.26M
                    dq = ((ac_dq * tok) >> dq_shift);
715
7.26M
                    assert(dq <= cf_max);
716
7.26M
                }
717
7.46M
                cul_level += tok;
718
7.46M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
7.46M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
7.46M
            } while (rc);
722
1.66M
        }
723
1.28M
    }
724
725
    // context
726
2.38M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
2.38M
    return eob;
729
1.97M
}
730
731
static void read_coef_tree(Dav1dTaskContext *const t,
732
                           const enum BlockSize bs, const Av1Block *const b,
733
                           const enum RectTxfmSize ytx, const int depth,
734
                           const uint16_t *const tx_split,
735
                           const int x_off, const int y_off, pixel *dst)
736
1.18M
{
737
1.18M
    const Dav1dFrameContext *const f = t->f;
738
1.18M
    Dav1dTileState *const ts = t->ts;
739
1.18M
    const Dav1dDSPContext *const dsp = f->dsp;
740
1.18M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
1.18M
    const int txw = t_dim->w, txh = t_dim->h;
742
743
    /* y_off can be larger than 3 since lossless blocks use TX_4X4 but can't
744
     * be splitted. Aviods an undefined left shift. */
745
1.18M
    if (depth < 2 && tx_split[depth] &&
746
66.6k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
52.3k
    {
748
52.3k
        const enum RectTxfmSize sub = t_dim->sub;
749
52.3k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
52.3k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
52.3k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
52.3k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
52.3k
        t->bx += txsw;
755
52.3k
        if (txw >= txh && t->bx < f->bw)
756
37.8k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
37.8k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
52.3k
        t->bx -= txsw;
759
52.3k
        t->by += txsh;
760
52.3k
        if (txh >= txw && t->by < f->bh) {
761
34.8k
            if (dst)
762
14.2k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
34.8k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
34.8k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
34.8k
            t->bx += txsw;
766
34.8k
            if (txw >= txh && t->bx < f->bw)
767
21.4k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
21.4k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
34.8k
            t->bx -= txsw;
770
34.8k
        }
771
52.3k
        t->by -= txsh;
772
1.13M
    } else {
773
1.13M
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
1.13M
        enum TxfmType txtp;
775
1.13M
        uint8_t cf_ctx;
776
1.13M
        int eob;
777
1.13M
        coef *cf;
778
779
1.13M
        if (t->frame_thread.pass) {
780
1.13M
            const int p = t->frame_thread.pass & 1;
781
1.13M
            assert(ts->frame_thread[p].cf);
782
1.13M
            cf = ts->frame_thread[p].cf;
783
1.13M
            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
784
18.4E
        } else {
785
18.4E
            cf = bitfn(t->cf);
786
18.4E
        }
787
1.13M
        if (t->frame_thread.pass != 2) {
788
706k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
706k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
706k
            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
706k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
706k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
706k
#define set_ctx(rep_macro) \
796
2.75M
            for (int y = 0; y < txh; y++) { \
797
2.05M
                rep_macro(txtp_map, 0, txtp); \
798
2.05M
                txtp_map += 32; \
799
2.05M
            }
800
706k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
706k
            case_set_upto16(t_dim->lw);
802
706k
#undef set_ctx
803
706k
            if (t->frame_thread.pass == 1)
804
706k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
706k
        } else {
806
424k
            const int cbi = *ts->frame_thread[0].cbi++;
807
424k
            eob  = cbi >> 5;
808
424k
            txtp = cbi & 0x1f;
809
424k
        }
810
1.13M
        if (!(t->frame_thread.pass & 1)) {
811
424k
            assert(dst);
812
424k
            if (eob >= 0) {
813
286k
                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
286k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
286k
                                              HIGHBD_CALL_SUFFIX);
817
286k
                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
286k
            }
820
424k
        }
821
1.13M
    }
822
1.18M
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
2.48M
{
827
2.48M
    const Dav1dFrameContext *const f = t->f;
828
2.48M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.48M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.48M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.48M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.48M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.48M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.48M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.48M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.08M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.97M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.48M
    if (b->skip) {
840
1.42M
        BlockContext *const a = t->a;
841
1.42M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.42M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.42M
        if (has_chroma) {
844
998k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
998k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
998k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
998k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
998k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
998k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
998k
        }
851
1.42M
        return;
852
1.42M
    }
853
854
1.05M
    Dav1dTileState *const ts = t->ts;
855
1.05M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
1.05M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
1.05M
    assert(t->frame_thread.pass == 1);
858
1.05M
    assert(!b->skip);
859
1.05M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
1.05M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
1.05M
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
2.14M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
1.09M
        const int sub_h4 = imin(h4, 16 + init_y);
865
2.22M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
1.12M
            const int sub_w4 = imin(w4, init_x + 16);
867
1.12M
            int y_off = !!init_y, y, x;
868
2.42M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.29M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.29M
            {
871
1.29M
                int x_off = !!init_x;
872
3.28M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.99M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.99M
                {
875
1.99M
                    if (!b->intra) {
876
650k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
650k
                                       x_off, y_off, NULL);
878
1.34M
                    } else {
879
1.34M
                        uint8_t cf_ctx = 0x40;
880
1.34M
                        enum TxfmType txtp;
881
1.34M
                        const int eob =
882
1.34M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.34M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.34M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.34M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
1.34M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.34M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.34M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.34M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.34M
                    }
893
1.99M
                }
894
1.29M
                t->bx -= x;
895
1.29M
            }
896
1.12M
            t->by -= y;
897
898
1.12M
            if (!has_chroma) continue;
899
900
941k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
941k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.82M
            for (int pl = 0; pl < 2; pl++) {
903
3.97M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
2.09M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
2.09M
                {
906
4.95M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.86M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.86M
                    {
909
2.86M
                        uint8_t cf_ctx = 0x40;
910
2.86M
                        enum TxfmType txtp;
911
2.86M
                        if (!b->intra)
912
1.25M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.25M
                                                        bx4 + (x << ss_hor)];
914
2.86M
                        const int eob =
915
2.86M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.86M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.86M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.86M
                                         &txtp, &cf_ctx);
919
2.86M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
2.86M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.86M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.86M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.86M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.86M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.86M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.86M
                    }
930
2.09M
                    t->bx -= x << ss_hor;
931
2.09M
                }
932
1.87M
                t->by -= y << ss_ver;
933
1.87M
            }
934
941k
        }
935
1.09M
    }
936
1.05M
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
1.30M
{
827
1.30M
    const Dav1dFrameContext *const f = t->f;
828
1.30M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.30M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.30M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.30M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.30M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.30M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.30M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.30M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.01M
                           (bw4 > ss_hor || t->bx & 1) &&
837
954k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.30M
    if (b->skip) {
840
784k
        BlockContext *const a = t->a;
841
784k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
784k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
784k
        if (has_chroma) {
844
498k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
498k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
498k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
498k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
498k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
498k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
498k
        }
851
784k
        return;
852
784k
    }
853
854
516k
    Dav1dTileState *const ts = t->ts;
855
516k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
516k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
516k
    assert(t->frame_thread.pass == 1);
858
516k
    assert(!b->skip);
859
516k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
516k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
516k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.04M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
533k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.07M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
544k
            const int sub_w4 = imin(w4, init_x + 16);
867
544k
            int y_off = !!init_y, y, x;
868
1.15M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
611k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
611k
            {
871
611k
                int x_off = !!init_x;
872
1.48M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
877k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
877k
                {
875
877k
                    if (!b->intra) {
876
218k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
218k
                                       x_off, y_off, NULL);
878
658k
                    } else {
879
658k
                        uint8_t cf_ctx = 0x40;
880
658k
                        enum TxfmType txtp;
881
658k
                        const int eob =
882
658k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
658k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
658k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
658k
                        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
658k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
658k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
658k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
658k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
658k
                    }
893
877k
                }
894
611k
                t->bx -= x;
895
611k
            }
896
544k
            t->by -= y;
897
898
544k
            if (!has_chroma) continue;
899
900
428k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
428k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.28M
            for (int pl = 0; pl < 2; pl++) {
903
1.78M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
926k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
926k
                {
906
2.08M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.16M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.16M
                    {
909
1.16M
                        uint8_t cf_ctx = 0x40;
910
1.16M
                        enum TxfmType txtp;
911
1.16M
                        if (!b->intra)
912
412k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
412k
                                                        bx4 + (x << ss_hor)];
914
1.16M
                        const int eob =
915
1.16M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.16M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.16M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.16M
                                         &txtp, &cf_ctx);
919
1.16M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.16M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.16M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.16M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.16M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.16M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.16M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.16M
                    }
930
926k
                    t->bx -= x << ss_hor;
931
926k
                }
932
854k
                t->by -= y << ss_ver;
933
854k
            }
934
428k
        }
935
533k
    }
936
516k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.18M
{
827
1.18M
    const Dav1dFrameContext *const f = t->f;
828
1.18M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.18M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.18M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.18M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.18M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.18M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.18M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.18M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.07M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.02M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.18M
    if (b->skip) {
840
641k
        BlockContext *const a = t->a;
841
641k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
641k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
641k
        if (has_chroma) {
844
500k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
500k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
500k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
500k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
500k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
500k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
500k
        }
851
641k
        return;
852
641k
    }
853
854
538k
    Dav1dTileState *const ts = t->ts;
855
538k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
538k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
538k
    assert(t->frame_thread.pass == 1);
858
538k
    assert(!b->skip);
859
538k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
538k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
538k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.10M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
561k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.14M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
581k
            const int sub_w4 = imin(w4, init_x + 16);
867
581k
            int y_off = !!init_y, y, x;
868
1.26M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
686k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
686k
            {
871
686k
                int x_off = !!init_x;
872
1.79M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.11M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.11M
                {
875
1.11M
                    if (!b->intra) {
876
431k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
431k
                                       x_off, y_off, NULL);
878
681k
                    } else {
879
681k
                        uint8_t cf_ctx = 0x40;
880
681k
                        enum TxfmType txtp;
881
681k
                        const int eob =
882
681k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
681k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
681k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
681k
                        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
681k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
681k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
681k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
681k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
681k
                    }
893
1.11M
                }
894
686k
                t->bx -= x;
895
686k
            }
896
581k
            t->by -= y;
897
898
581k
            if (!has_chroma) continue;
899
900
513k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
513k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.53M
            for (int pl = 0; pl < 2; pl++) {
903
2.19M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.17M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.17M
                {
906
2.87M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.70M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.70M
                    {
909
1.70M
                        uint8_t cf_ctx = 0x40;
910
1.70M
                        enum TxfmType txtp;
911
1.70M
                        if (!b->intra)
912
843k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
843k
                                                        bx4 + (x << ss_hor)];
914
1.70M
                        const int eob =
915
1.70M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.70M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.70M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.70M
                                         &txtp, &cf_ctx);
919
1.70M
                        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.70M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.70M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.70M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.70M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.70M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.70M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.70M
                    }
930
1.17M
                    t->bx -= x << ss_hor;
931
1.17M
                }
932
1.02M
                t->by -= y << ss_ver;
933
1.02M
            }
934
513k
        }
935
561k
    }
936
538k
}
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.48M
{
945
1.48M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
1.48M
    const Dav1dFrameContext *const f = t->f;
947
1.48M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
1.48M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
1.48M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
1.48M
    const int mvx = mv.x, mvy = mv.y;
951
1.48M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
1.48M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
1.48M
    const pixel *ref;
954
955
1.48M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
929k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
929k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
929k
        int w, h;
959
960
929k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
750k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
750k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
750k
        } else {
964
179k
            w = f->bw * 4 >> ss_hor;
965
179k
            h = f->bh * 4 >> ss_ver;
966
179k
        }
967
929k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
769k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
520k
            dy + bh4 * v_mul + !!my * 4 > h)
970
493k
        {
971
493k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
493k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
493k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
493k
                                emu_edge_buf, 192 * sizeof(pixel),
975
493k
                                refp->p.data[pl], ref_stride);
976
493k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
493k
            ref_stride = 192 * sizeof(pixel);
978
493k
        } else {
979
435k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
435k
        }
981
982
929k
        if (dst8 != NULL) {
983
686k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
686k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
686k
                                     HIGHBD_CALL_SUFFIX);
986
686k
        } else {
987
243k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
243k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
243k
                                      HIGHBD_CALL_SUFFIX);
990
243k
        }
991
929k
    } else {
992
551k
        assert(refp != &f->sr_cur);
993
994
551k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
551k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
1.10M
#define scale_mv(res, val, scale) do { \
997
1.10M
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
1.10M
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
1.10M
        } while (0)
1000
551k
        int pos_y, pos_x;
1001
551k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
551k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
551k
#undef scale_mv
1004
551k
        const int left = pos_x >> 10;
1005
551k
        const int top = pos_y >> 10;
1006
551k
        const int right =
1007
551k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
551k
        const int bottom =
1009
551k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
551k
        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
551k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
551k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
551k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
304k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
304k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
304k
                                w, h, left - 3, top - 3,
1023
304k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
304k
                                refp->p.data[pl], ref_stride);
1025
304k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
304k
            ref_stride = 320 * sizeof(pixel);
1027
304k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
304k
        } else {
1029
247k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
247k
        }
1031
1032
551k
        if (dst8 != NULL) {
1033
360k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
360k
                                            bw4 * h_mul, bh4 * v_mul,
1035
360k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
360k
                                            f->svc[refidx][0].step,
1037
360k
                                            f->svc[refidx][1].step
1038
360k
                                            HIGHBD_CALL_SUFFIX);
1039
360k
        } else {
1040
191k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
191k
                                             bw4 * h_mul, bh4 * v_mul,
1042
191k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
191k
                                             f->svc[refidx][0].step,
1044
191k
                                             f->svc[refidx][1].step
1045
191k
                                             HIGHBD_CALL_SUFFIX);
1046
191k
        }
1047
551k
    }
1048
1049
1.48M
    return 0;
1050
1.48M
}
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
117k
{
1057
117k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
117k
    const Dav1dFrameContext *const f = t->f;
1059
117k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
117k
    pixel *const lap = bitfn(t->scratch.lap);
1061
117k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
117k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
117k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
117k
    int res;
1065
1066
117k
    if (t->by > t->ts->tiling.row_start &&
1067
105k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
97.6k
    {
1069
205k
        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
108k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
108k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
108k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
108k
            if (a_r->ref.ref[0] > 0) {
1076
105k
                const int ow4 = imin(step4, b_dim[0]);
1077
105k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
105k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
105k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
105k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
105k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
105k
                if (res) return res;
1083
105k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
105k
                                   h_mul * ow4, v_mul * oh4);
1085
105k
                i++;
1086
105k
            }
1087
108k
            x += step4;
1088
108k
        }
1089
97.6k
    }
1090
1091
117k
    if (t->bx > t->ts->tiling.col_start)
1092
209k
        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
109k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
109k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
109k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
109k
            if (l_r->ref.ref[0] > 0) {
1099
107k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
107k
                const int oh4 = imin(step4, b_dim[1]);
1101
107k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
107k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
107k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
107k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
107k
                if (res) return res;
1106
107k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
107k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
107k
                i++;
1109
107k
            }
1110
109k
            y += step4;
1111
109k
        }
1112
117k
    return 0;
1113
117k
}
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
27.8k
{
1121
27.8k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
27.8k
    const Dav1dFrameContext *const f = t->f;
1123
27.8k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
27.8k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
27.8k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
27.8k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
27.8k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
27.8k
    const int32_t *const mat = wmp->matrix;
1129
27.8k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
27.8k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
100k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
72.5k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
72.5k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
72.5k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
362k
        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
290k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
290k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
290k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
290k
            const int dx = (int) (mvx >> 16) - 4;
1144
290k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
290k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
290k
            const int dy = (int) (mvy >> 16) - 4;
1147
290k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
290k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
290k
            const pixel *ref_ptr;
1151
290k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
290k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
209k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
209k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
209k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
209k
                                    refp->p.data[pl], ref_stride);
1158
209k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
209k
                ref_stride = 32 * sizeof(pixel);
1160
209k
            } else {
1161
80.7k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
80.7k
            }
1163
290k
            if (dst16 != NULL)
1164
43.4k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
43.4k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
246k
            else
1167
246k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
246k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
290k
        }
1170
72.5k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
13.1k
        else      dst16 += 8 * dstride;
1172
72.5k
    }
1173
27.8k
    return 0;
1174
27.8k
}
1175
1176
void bytefn(dav1d_recon_b_intra)(Dav1dTaskContext *const t, const enum BlockSize bs,
1177
                                 const enum EdgeFlags intra_edge_flags,
1178
                                 const Av1Block *const b)
1179
1.09M
{
1180
1.09M
    Dav1dTileState *const ts = t->ts;
1181
1.09M
    const Dav1dFrameContext *const f = t->f;
1182
1.09M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.09M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.09M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.09M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.09M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.09M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.09M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.09M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.09M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.09M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
845k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
785k
                           (bh4 > ss_ver || t->by & 1);
1194
1.09M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.09M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.09M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.09M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.09M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.22M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.12M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.12M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.27M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.15M
            if (b->pal_sz[0]) {
1208
10.9k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
10.9k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
10.9k
                const uint8_t *pal_idx;
1211
10.9k
                if (t->frame_thread.pass) {
1212
10.9k
                    const int p = t->frame_thread.pass & 1;
1213
10.9k
                    assert(ts->frame_thread[p].pal_idx);
1214
10.9k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
10.9k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
10.9k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
10.9k
                const pixel *const pal = t->frame_thread.pass ?
1220
10.9k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
10.9k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
10.9k
                    bytefn(t->scratch.pal)[0];
1223
10.9k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
10.9k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
10.9k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
10.9k
            }
1229
1230
1.15M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.15M
                                     sm_flag(&t->l, by4) |
1232
1.15M
                                     intra_edge_filter_flag);
1233
1.15M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.12M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.15M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.12M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.15M
            int y, x;
1238
1.15M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.51M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.35M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.35M
            {
1242
1.35M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.35M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.35M
                                    t->bx + init_x);
1245
3.31M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.95M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.95M
                {
1248
1.95M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.94M
                    int angle = b->y_angle;
1251
1.94M
                    const enum EdgeFlags edge_flags =
1252
1.94M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.38M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.94M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.25M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.94M
                    const pixel *top_sb_edge = NULL;
1257
1.94M
                    if (!(t->by & (f->sb_step - 1))) {
1258
489k
                        top_sb_edge = f->ipred_edge[0];
1259
489k
                        const int sby = t->by >> f->sb_shift;
1260
489k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
489k
                    }
1262
1.94M
                    const enum IntraPredMode m =
1263
1.94M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.94M
                                                          t->bx > ts->tiling.col_start,
1265
1.94M
                                                          t->by,
1266
1.94M
                                                          t->by > ts->tiling.row_start,
1267
1.94M
                                                          ts->tiling.col_end,
1268
1.94M
                                                          ts->tiling.row_end,
1269
1.94M
                                                          edge_flags, dst,
1270
1.94M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.94M
                                                          b->y_mode, &angle,
1272
1.94M
                                                          t_dim->w, t_dim->h,
1273
1.94M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.94M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.94M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.94M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.94M
                                             angle | intra_flags,
1278
1.94M
                                             4 * f->bw - 4 * t->bx,
1279
1.94M
                                             4 * f->bh - 4 * t->by
1280
1.94M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.94M
                    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.95M
                skip_y_pred: {}
1293
1.95M
                    if (!b->skip) {
1294
620k
                        coef *cf;
1295
620k
                        int eob;
1296
620k
                        enum TxfmType txtp;
1297
620k
                        if (t->frame_thread.pass) {
1298
620k
                            const int p = t->frame_thread.pass & 1;
1299
620k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
620k
                            cf = ts->frame_thread[p].cf;
1301
620k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
620k
                            eob  = cbi >> 5;
1303
620k
                            txtp = cbi & 0x1f;
1304
18.4E
                        } else {
1305
18.4E
                            uint8_t cf_ctx;
1306
18.4E
                            cf = bitfn(t->cf);
1307
18.4E
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
18.4E
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
18.4E
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
18.4E
                            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
18.4E
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
18.4E
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
18.4E
                        }
1316
620k
                        if (eob >= 0) {
1317
425k
                            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
425k
                            dsp->itx.itxfm_add[b->tx]
1321
425k
                                              [txtp](dst,
1322
425k
                                                     f->cur.stride[0],
1323
425k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
425k
                            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
425k
                        }
1328
1.33M
                    } 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.95M
                    dst += 4 * t_dim->w;
1333
1.95M
                }
1334
1.35M
                t->bx -= x;
1335
1.35M
            }
1336
1.15M
            t->by -= y;
1337
1338
1.15M
            if (!has_chroma) continue;
1339
1340
777k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
777k
            if (b->uv_mode == CFL_PRED) {
1343
157k
                assert(!init_x && !init_y);
1344
1345
157k
                int16_t *const ac = t->scratch.ac;
1346
157k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
157k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
157k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
157k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
157k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
157k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
157k
                const int furthest_r =
1354
157k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
157k
                const int furthest_b =
1356
157k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
157k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
157k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
157k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
157k
                                                         cbw4 * 4, cbh4 * 4);
1361
471k
                for (int pl = 0; pl < 2; pl++) {
1362
314k
                    if (!b->cfl_alpha[pl]) continue;
1363
255k
                    int angle = 0;
1364
255k
                    const pixel *top_sb_edge = NULL;
1365
255k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
85.1k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
85.1k
                        const int sby = t->by >> f->sb_shift;
1368
85.1k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
85.1k
                    }
1370
255k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
255k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
255k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
255k
                    const enum IntraPredMode m =
1374
255k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
255k
                                                          ypos, ypos > ystart,
1376
255k
                                                          ts->tiling.col_end >> ss_hor,
1377
255k
                                                          ts->tiling.row_end >> ss_ver,
1378
255k
                                                          0, uv_dst[pl], stride,
1379
255k
                                                          top_sb_edge, DC_PRED, &angle,
1380
255k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
255k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
255k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
255k
                                           uv_t_dim->w * 4,
1384
255k
                                           uv_t_dim->h * 4,
1385
255k
                                           ac, b->cfl_alpha[pl]
1386
255k
                                           HIGHBD_CALL_SUFFIX);
1387
255k
                }
1388
157k
                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
620k
            } else if (b->pal_sz[1]) {
1394
2.24k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.24k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.24k
                const pixel (*pal)[8];
1397
2.24k
                const uint8_t *pal_idx;
1398
2.24k
                if (t->frame_thread.pass) {
1399
2.24k
                    const int p = t->frame_thread.pass & 1;
1400
2.24k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.24k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.24k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.24k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.24k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.24k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.24k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.24k
                                       f->cur.stride[1], pal[1],
1412
2.24k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.24k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.24k
                                       f->cur.stride[1], pal[2],
1415
2.24k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.24k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
2.24k
            }
1425
1426
777k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
777k
                                 sm_uv_flag(&t->l, cby4);
1428
777k
            const int uv_sb_has_tr =
1429
777k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
748k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
777k
            const int uv_sb_has_bl =
1432
777k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
748k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
777k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.33M
            for (int pl = 0; pl < 2; pl++) {
1436
3.25M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.69M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.69M
                {
1439
1.69M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.69M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.69M
                                        ((t->bx + init_x) >> ss_hor));
1442
3.70M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.01M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.01M
                    {
1445
2.01M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.75M
                            b->pal_sz[1])
1447
261k
                        {
1448
261k
                            goto skip_uv_pred;
1449
261k
                        }
1450
1451
1.75M
                        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.75M
                        const enum EdgeFlags edge_flags =
1456
1.75M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
753k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.24M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.75M
                            ((x > (init_x >> ss_hor) ||
1460
1.43M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.04M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.75M
                        const pixel *top_sb_edge = NULL;
1463
1.75M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
556k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
556k
                            const int sby = t->by >> f->sb_shift;
1466
556k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
556k
                        }
1468
1.75M
                        const enum IntraPredMode uv_mode =
1469
1.75M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.75M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.75M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.75M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.75M
                        const enum IntraPredMode m =
1474
1.75M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.75M
                                                              ypos, ypos > ystart,
1476
1.75M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.75M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.75M
                                                              edge_flags, dst, stride,
1479
1.75M
                                                              top_sb_edge, uv_mode,
1480
1.75M
                                                              &angle, uv_t_dim->w,
1481
1.75M
                                                              uv_t_dim->h,
1482
1.75M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.75M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.75M
                        angle |= intra_edge_filter_flag;
1485
1.75M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.75M
                                                 uv_t_dim->w * 4,
1487
1.75M
                                                 uv_t_dim->h * 4,
1488
1.75M
                                                 angle | sm_uv_fl,
1489
1.75M
                                                 (4 * f->bw + ss_hor -
1490
1.75M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.75M
                                                 (4 * f->bh + ss_ver -
1492
1.75M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.75M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.75M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.01M
                    skip_uv_pred: {}
1505
2.01M
                        if (!b->skip) {
1506
751k
                            enum TxfmType txtp;
1507
751k
                            int eob;
1508
751k
                            coef *cf;
1509
751k
                            if (t->frame_thread.pass) {
1510
751k
                                const int p = t->frame_thread.pass & 1;
1511
751k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
751k
                                cf = ts->frame_thread[p].cf;
1513
751k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
751k
                                eob  = cbi >> 5;
1515
751k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
751k
                            if (eob >= 0) {
1533
238k
                                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
238k
                                dsp->itx.itxfm_add[b->uvtx]
1537
238k
                                                  [txtp](dst, stride,
1538
238k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
238k
                                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
238k
                            }
1543
1.26M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
2.01M
                        dst += uv_t_dim->w * 4;
1548
2.01M
                    }
1549
1.69M
                    t->bx -= x << ss_hor;
1550
1.69M
                }
1551
1.55M
                t->by -= y << ss_ver;
1552
1.55M
            }
1553
777k
        }
1554
1.12M
    }
1555
1.09M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
603k
{
1180
603k
    Dav1dTileState *const ts = t->ts;
1181
603k
    const Dav1dFrameContext *const f = t->f;
1182
603k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
603k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
603k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
603k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
603k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
603k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
603k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
603k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
603k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
603k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
402k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
370k
                           (bh4 > ss_ver || t->by & 1);
1194
603k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
603k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
603k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
603k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
603k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.21M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
612k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
612k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.23M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
624k
            if (b->pal_sz[0]) {
1208
5.50k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
5.50k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
5.50k
                const uint8_t *pal_idx;
1211
5.50k
                if (t->frame_thread.pass) {
1212
5.50k
                    const int p = t->frame_thread.pass & 1;
1213
5.50k
                    assert(ts->frame_thread[p].pal_idx);
1214
5.50k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
5.50k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
5.50k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
5.50k
                const pixel *const pal = t->frame_thread.pass ?
1220
5.50k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
5.50k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
5.50k
                    bytefn(t->scratch.pal)[0];
1223
5.50k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
5.50k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
5.50k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
5.50k
            }
1229
1230
624k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
624k
                                     sm_flag(&t->l, by4) |
1232
624k
                                     intra_edge_filter_flag);
1233
624k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
612k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
624k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
612k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
624k
            int y, x;
1238
624k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.35M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
732k
                 y += t_dim->h, t->by += t_dim->h)
1241
732k
            {
1242
732k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
732k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
732k
                                    t->bx + init_x);
1245
1.75M
                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
712k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.01M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
645k
                             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
265k
                        top_sb_edge = f->ipred_edge[0];
1259
265k
                        const int sby = t->by >> f->sb_shift;
1260
265k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
265k
                    }
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
283k
                        coef *cf;
1295
283k
                        int eob;
1296
283k
                        enum TxfmType txtp;
1297
283k
                        if (t->frame_thread.pass) {
1298
283k
                            const int p = t->frame_thread.pass & 1;
1299
283k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
283k
                            cf = ts->frame_thread[p].cf;
1301
283k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
283k
                            eob  = cbi >> 5;
1303
283k
                            txtp = cbi & 0x1f;
1304
283k
                        } 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
283k
                        if (eob >= 0) {
1317
197k
                            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
197k
                            dsp->itx.itxfm_add[b->tx]
1321
197k
                                              [txtp](dst,
1322
197k
                                                     f->cur.stride[0],
1323
197k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
197k
                            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
197k
                        }
1328
737k
                    } 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
732k
                t->bx -= x;
1335
732k
            }
1336
624k
            t->by -= y;
1337
1338
624k
            if (!has_chroma) continue;
1339
1340
359k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
359k
            if (b->uv_mode == CFL_PRED) {
1343
71.8k
                assert(!init_x && !init_y);
1344
1345
71.8k
                int16_t *const ac = t->scratch.ac;
1346
71.8k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
71.8k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
71.8k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
71.8k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
71.8k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
71.8k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
71.8k
                const int furthest_r =
1354
71.8k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
71.8k
                const int furthest_b =
1356
71.8k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
71.8k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
71.8k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
71.8k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
71.8k
                                                         cbw4 * 4, cbh4 * 4);
1361
215k
                for (int pl = 0; pl < 2; pl++) {
1362
143k
                    if (!b->cfl_alpha[pl]) continue;
1363
116k
                    int angle = 0;
1364
116k
                    const pixel *top_sb_edge = NULL;
1365
116k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
38.8k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
38.8k
                        const int sby = t->by >> f->sb_shift;
1368
38.8k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
38.8k
                    }
1370
116k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
116k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
116k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
116k
                    const enum IntraPredMode m =
1374
116k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
116k
                                                          ypos, ypos > ystart,
1376
116k
                                                          ts->tiling.col_end >> ss_hor,
1377
116k
                                                          ts->tiling.row_end >> ss_ver,
1378
116k
                                                          0, uv_dst[pl], stride,
1379
116k
                                                          top_sb_edge, DC_PRED, &angle,
1380
116k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
116k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
116k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
116k
                                           uv_t_dim->w * 4,
1384
116k
                                           uv_t_dim->h * 4,
1385
116k
                                           ac, b->cfl_alpha[pl]
1386
116k
                                           HIGHBD_CALL_SUFFIX);
1387
116k
                }
1388
71.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
287k
            } else if (b->pal_sz[1]) {
1394
595
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
595
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
595
                const pixel (*pal)[8];
1397
595
                const uint8_t *pal_idx;
1398
595
                if (t->frame_thread.pass) {
1399
595
                    const int p = t->frame_thread.pass & 1;
1400
595
                    assert(ts->frame_thread[p].pal_idx);
1401
595
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
595
                                              ((t->bx >> 1) + (t->by & 1))];
1403
595
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
595
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
595
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
595
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
595
                                       f->cur.stride[1], pal[1],
1412
595
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
595
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
595
                                       f->cur.stride[1], pal[2],
1415
595
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
595
                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
595
            }
1425
1426
359k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
359k
                                 sm_uv_flag(&t->l, cby4);
1428
359k
            const int uv_sb_has_tr =
1429
359k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
348k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
359k
            const int uv_sb_has_bl =
1432
359k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
348k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
359k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.07M
            for (int pl = 0; pl < 2; pl++) {
1436
1.49M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
781k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
781k
                {
1439
781k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
781k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
781k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.72M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
948k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
948k
                    {
1445
948k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
831k
                            b->pal_sz[1])
1447
119k
                        {
1448
119k
                            goto skip_uv_pred;
1449
119k
                        }
1450
1451
829k
                        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
829k
                        const enum EdgeFlags edge_flags =
1456
829k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
366k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
594k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
829k
                            ((x > (init_x >> ss_hor) ||
1460
662k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
505k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
829k
                        const pixel *top_sb_edge = NULL;
1463
829k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
259k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
259k
                            const int sby = t->by >> f->sb_shift;
1466
259k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
259k
                        }
1468
829k
                        const enum IntraPredMode uv_mode =
1469
829k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
829k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
829k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
829k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
829k
                        const enum IntraPredMode m =
1474
829k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
829k
                                                              ypos, ypos > ystart,
1476
829k
                                                              ts->tiling.col_end >> ss_hor,
1477
829k
                                                              ts->tiling.row_end >> ss_ver,
1478
829k
                                                              edge_flags, dst, stride,
1479
829k
                                                              top_sb_edge, uv_mode,
1480
829k
                                                              &angle, uv_t_dim->w,
1481
829k
                                                              uv_t_dim->h,
1482
829k
                                                              f->seq_hdr->intra_edge_filter,
1483
829k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
829k
                        angle |= intra_edge_filter_flag;
1485
829k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
829k
                                                 uv_t_dim->w * 4,
1487
829k
                                                 uv_t_dim->h * 4,
1488
829k
                                                 angle | sm_uv_fl,
1489
829k
                                                 (4 * f->bw + ss_hor -
1490
829k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
829k
                                                 (4 * f->bh + ss_ver -
1492
829k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
829k
                                                 HIGHBD_CALL_SUFFIX);
1494
829k
                        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
948k
                    skip_uv_pred: {}
1505
948k
                        if (!b->skip) {
1506
307k
                            enum TxfmType txtp;
1507
307k
                            int eob;
1508
307k
                            coef *cf;
1509
307k
                            if (t->frame_thread.pass) {
1510
307k
                                const int p = t->frame_thread.pass & 1;
1511
307k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
307k
                                cf = ts->frame_thread[p].cf;
1513
307k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
307k
                                eob  = cbi >> 5;
1515
307k
                                txtp = cbi & 0x1f;
1516
307k
                            } else {
1517
2
                                uint8_t cf_ctx;
1518
2
                                cf = bitfn(t->cf);
1519
2
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
2
                                                   &t->l.ccoef[pl][cby4 + y],
1521
2
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
2
                                                   &txtp, &cf_ctx);
1523
2
                                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
2
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
2
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
2
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
2
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
2
                            }
1532
307k
                            if (eob >= 0) {
1533
110k
                                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
110k
                                dsp->itx.itxfm_add[b->uvtx]
1537
110k
                                                  [txtp](dst, stride,
1538
110k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
110k
                                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
110k
                            }
1543
640k
                        } 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
948k
                        dst += uv_t_dim->w * 4;
1548
948k
                    }
1549
781k
                    t->bx -= x << ss_hor;
1550
781k
                }
1551
718k
                t->by -= y << ss_ver;
1552
718k
            }
1553
359k
        }
1554
612k
    }
1555
603k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
496k
{
1180
496k
    Dav1dTileState *const ts = t->ts;
1181
496k
    const Dav1dFrameContext *const f = t->f;
1182
496k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
496k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
496k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
496k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
496k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
496k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
496k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
496k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
496k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
496k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
443k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
415k
                           (bh4 > ss_ver || t->by & 1);
1194
496k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
496k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
496k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
496k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
496k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.00M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
511k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
511k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.03M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
531k
            if (b->pal_sz[0]) {
1208
5.43k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
5.43k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
5.43k
                const uint8_t *pal_idx;
1211
5.43k
                if (t->frame_thread.pass) {
1212
5.43k
                    const int p = t->frame_thread.pass & 1;
1213
5.43k
                    assert(ts->frame_thread[p].pal_idx);
1214
5.43k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
5.43k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
5.43k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
5.43k
                const pixel *const pal = t->frame_thread.pass ?
1220
5.43k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
5.43k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
5.43k
                    bytefn(t->scratch.pal)[0];
1223
5.43k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
5.43k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
5.43k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
5.43k
            }
1229
1230
531k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
531k
                                     sm_flag(&t->l, by4) |
1232
531k
                                     intra_edge_filter_flag);
1233
531k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
510k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
531k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
510k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
531k
            int y, x;
1238
531k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.15M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
622k
                 y += t_dim->h, t->by += t_dim->h)
1241
624k
            {
1242
624k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
624k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
624k
                                    t->bx + init_x);
1245
1.55M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
932k
                     x += t_dim->w, t->bx += t_dim->w)
1247
934k
                {
1248
934k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
927k
                    int angle = b->y_angle;
1251
927k
                    const enum EdgeFlags edge_flags =
1252
927k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
674k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
927k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
607k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
927k
                    const pixel *top_sb_edge = NULL;
1257
927k
                    if (!(t->by & (f->sb_step - 1))) {
1258
223k
                        top_sb_edge = f->ipred_edge[0];
1259
223k
                        const int sby = t->by >> f->sb_shift;
1260
223k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
223k
                    }
1262
927k
                    const enum IntraPredMode m =
1263
927k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
927k
                                                          t->bx > ts->tiling.col_start,
1265
927k
                                                          t->by,
1266
927k
                                                          t->by > ts->tiling.row_start,
1267
927k
                                                          ts->tiling.col_end,
1268
927k
                                                          ts->tiling.row_end,
1269
927k
                                                          edge_flags, dst,
1270
927k
                                                          f->cur.stride[0], top_sb_edge,
1271
927k
                                                          b->y_mode, &angle,
1272
927k
                                                          t_dim->w, t_dim->h,
1273
927k
                                                          f->seq_hdr->intra_edge_filter,
1274
927k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
927k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
927k
                                             t_dim->w * 4, t_dim->h * 4,
1277
927k
                                             angle | intra_flags,
1278
927k
                                             4 * f->bw - 4 * t->bx,
1279
927k
                                             4 * f->bh - 4 * t->by
1280
927k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
927k
                    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
932k
                skip_y_pred: {}
1293
932k
                    if (!b->skip) {
1294
337k
                        coef *cf;
1295
337k
                        int eob;
1296
337k
                        enum TxfmType txtp;
1297
337k
                        if (t->frame_thread.pass) {
1298
337k
                            const int p = t->frame_thread.pass & 1;
1299
337k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
337k
                            cf = ts->frame_thread[p].cf;
1301
337k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
337k
                            eob  = cbi >> 5;
1303
337k
                            txtp = cbi & 0x1f;
1304
18.4E
                        } else {
1305
18.4E
                            uint8_t cf_ctx;
1306
18.4E
                            cf = bitfn(t->cf);
1307
18.4E
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
18.4E
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
18.4E
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
18.4E
                            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
18.4E
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
18.4E
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
18.4E
                        }
1316
337k
                        if (eob >= 0) {
1317
228k
                            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
228k
                            dsp->itx.itxfm_add[b->tx]
1321
228k
                                              [txtp](dst,
1322
228k
                                                     f->cur.stride[0],
1323
228k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
228k
                            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
228k
                        }
1328
595k
                    } 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
932k
                    dst += 4 * t_dim->w;
1333
932k
                }
1334
622k
                t->bx -= x;
1335
622k
            }
1336
529k
            t->by -= y;
1337
1338
529k
            if (!has_chroma) continue;
1339
1340
417k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
417k
            if (b->uv_mode == CFL_PRED) {
1343
85.3k
                assert(!init_x && !init_y);
1344
1345
85.3k
                int16_t *const ac = t->scratch.ac;
1346
85.3k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
85.3k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
85.3k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
85.3k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
85.3k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
85.3k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
85.3k
                const int furthest_r =
1354
85.3k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
85.3k
                const int furthest_b =
1356
85.3k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
85.3k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
85.3k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
85.3k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
85.3k
                                                         cbw4 * 4, cbh4 * 4);
1361
255k
                for (int pl = 0; pl < 2; pl++) {
1362
170k
                    if (!b->cfl_alpha[pl]) continue;
1363
138k
                    int angle = 0;
1364
138k
                    const pixel *top_sb_edge = NULL;
1365
138k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
46.2k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
46.2k
                        const int sby = t->by >> f->sb_shift;
1368
46.2k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
46.2k
                    }
1370
138k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
138k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
138k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
138k
                    const enum IntraPredMode m =
1374
138k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
138k
                                                          ypos, ypos > ystart,
1376
138k
                                                          ts->tiling.col_end >> ss_hor,
1377
138k
                                                          ts->tiling.row_end >> ss_ver,
1378
138k
                                                          0, uv_dst[pl], stride,
1379
138k
                                                          top_sb_edge, DC_PRED, &angle,
1380
138k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
138k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
138k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
138k
                                           uv_t_dim->w * 4,
1384
138k
                                           uv_t_dim->h * 4,
1385
138k
                                           ac, b->cfl_alpha[pl]
1386
138k
                                           HIGHBD_CALL_SUFFIX);
1387
138k
                }
1388
85.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
332k
            } else if (b->pal_sz[1]) {
1394
1.64k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.64k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.64k
                const pixel (*pal)[8];
1397
1.64k
                const uint8_t *pal_idx;
1398
1.64k
                if (t->frame_thread.pass) {
1399
1.64k
                    const int p = t->frame_thread.pass & 1;
1400
1.64k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.64k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.64k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.64k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.64k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.64k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.64k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.64k
                                       f->cur.stride[1], pal[1],
1412
1.64k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.64k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.64k
                                       f->cur.stride[1], pal[2],
1415
1.64k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.64k
                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.64k
            }
1425
1426
417k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
417k
                                 sm_uv_flag(&t->l, cby4);
1428
417k
            const int uv_sb_has_tr =
1429
417k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
399k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
417k
            const int uv_sb_has_bl =
1432
417k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
399k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
417k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.25M
            for (int pl = 0; pl < 2; pl++) {
1436
1.75M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
910k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
912k
                {
1439
912k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
912k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
912k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.97M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.06M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.06M
                    {
1445
1.06M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
925k
                            b->pal_sz[1])
1447
142k
                        {
1448
142k
                            goto skip_uv_pred;
1449
142k
                        }
1450
1451
922k
                        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
922k
                        const enum EdgeFlags edge_flags =
1456
922k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
386k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
645k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
922k
                            ((x > (init_x >> ss_hor) ||
1460
770k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
541k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
922k
                        const pixel *top_sb_edge = NULL;
1463
922k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
296k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
296k
                            const int sby = t->by >> f->sb_shift;
1466
296k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
296k
                        }
1468
922k
                        const enum IntraPredMode uv_mode =
1469
922k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
922k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
922k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
922k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
922k
                        const enum IntraPredMode m =
1474
922k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
922k
                                                              ypos, ypos > ystart,
1476
922k
                                                              ts->tiling.col_end >> ss_hor,
1477
922k
                                                              ts->tiling.row_end >> ss_ver,
1478
922k
                                                              edge_flags, dst, stride,
1479
922k
                                                              top_sb_edge, uv_mode,
1480
922k
                                                              &angle, uv_t_dim->w,
1481
922k
                                                              uv_t_dim->h,
1482
922k
                                                              f->seq_hdr->intra_edge_filter,
1483
922k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
922k
                        angle |= intra_edge_filter_flag;
1485
922k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
922k
                                                 uv_t_dim->w * 4,
1487
922k
                                                 uv_t_dim->h * 4,
1488
922k
                                                 angle | sm_uv_fl,
1489
922k
                                                 (4 * f->bw + ss_hor -
1490
922k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
922k
                                                 (4 * f->bh + ss_ver -
1492
922k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
922k
                                                 HIGHBD_CALL_SUFFIX);
1494
922k
                        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.06M
                    skip_uv_pred: {}
1505
1.06M
                        if (!b->skip) {
1506
443k
                            enum TxfmType txtp;
1507
443k
                            int eob;
1508
443k
                            coef *cf;
1509
443k
                            if (t->frame_thread.pass) {
1510
443k
                                const int p = t->frame_thread.pass & 1;
1511
443k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
443k
                                cf = ts->frame_thread[p].cf;
1513
443k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
443k
                                eob  = cbi >> 5;
1515
443k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
443k
                            if (eob >= 0) {
1533
128k
                                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
128k
                                dsp->itx.itxfm_add[b->uvtx]
1537
128k
                                                  [txtp](dst, stride,
1538
128k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
128k
                                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
128k
                            }
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
1.06M
                        dst += uv_t_dim->w * 4;
1548
1.06M
                    }
1549
910k
                    t->bx -= x << ss_hor;
1550
910k
                }
1551
838k
                t->by -= y << ss_ver;
1552
838k
            }
1553
417k
        }
1554
511k
    }
1555
496k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
389k
{
1560
389k
    Dav1dTileState *const ts = t->ts;
1561
389k
    const Dav1dFrameContext *const f = t->f;
1562
389k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
389k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
389k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
389k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
389k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
389k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
389k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
389k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
389k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
349k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
335k
                           (bh4 > ss_ver || t->by & 1);
1573
389k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
389k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
389k
    int res;
1576
1577
    // prediction
1578
389k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
389k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
389k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
389k
    const ptrdiff_t uvdstoff =
1582
389k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
389k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
75.1k
        assert(!f->frame_hdr->super_res.enabled);
1586
75.1k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
75.1k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
75.1k
        if (res) return res;
1589
156k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
104k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
104k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
104k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
104k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
104k
            if (res) return res;
1595
104k
        }
1596
314k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
237k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
237k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
237k
        if (imin(bw4, bh4) > 1 &&
1601
132k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
129k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
6.69k
        {
1604
6.69k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
6.69k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
6.69k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
6.69k
            if (res) return res;
1608
230k
        } else {
1609
230k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
230k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
230k
            if (res) return res;
1612
230k
            if (b->motion_mode == MM_OBMC) {
1613
40.1k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
40.1k
                if (res) return res;
1615
40.1k
            }
1616
230k
        }
1617
237k
        if (b->interintra_type) {
1618
7.69k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
7.69k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
6.16k
                                   SMOOTH_PRED : b->interintra_mode;
1621
7.69k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
7.69k
            int angle = 0;
1623
7.69k
            const pixel *top_sb_edge = NULL;
1624
7.69k
            if (!(t->by & (f->sb_step - 1))) {
1625
2.71k
                top_sb_edge = f->ipred_edge[0];
1626
2.71k
                const int sby = t->by >> f->sb_shift;
1627
2.71k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
2.71k
            }
1629
7.69k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
7.69k
                                                  t->by, t->by > ts->tiling.row_start,
1631
7.69k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
7.69k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
7.69k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
7.69k
                                                  HIGHBD_CALL_SUFFIX);
1635
7.69k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
7.69k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
7.69k
                                     HIGHBD_CALL_SUFFIX);
1638
7.69k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
7.69k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
7.69k
        }
1641
1642
237k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
201k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
201k
        refmvs_block *const *r;
1647
201k
        if (is_sub8x8) {
1648
12.0k
            assert(ss_hor == 1);
1649
12.0k
            r = &t->rt.r[(t->by & 31) + 5];
1650
12.0k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
12.0k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
12.0k
            if (bw4 == 1 && bh4 == ss_ver)
1653
3.77k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
12.0k
        }
1655
1656
        // chroma prediction
1657
201k
        if (is_sub8x8) {
1658
10.8k
            assert(ss_hor == 1);
1659
10.8k
            ptrdiff_t h_off = 0, v_off = 0;
1660
10.8k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
8.03k
                for (int pl = 0; pl < 2; pl++) {
1662
5.35k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
5.35k
                             NULL, f->cur.stride[1],
1664
5.35k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
5.35k
                             r[-1][t->bx - 1].mv.mv[0],
1666
5.35k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
5.35k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
5.35k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
5.35k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
5.35k
                    if (res) return res;
1671
5.35k
                }
1672
2.67k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
2.67k
                h_off = 2;
1674
2.67k
            }
1675
10.8k
            if (bw4 == 1) {
1676
7.74k
                const enum Filter2d left_filter_2d =
1677
7.74k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
23.2k
                for (int pl = 0; pl < 2; pl++) {
1679
15.4k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
15.4k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
15.4k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
15.4k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
15.4k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
15.4k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
15.4k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
15.4k
                    if (res) return res;
1687
15.4k
                }
1688
7.74k
                h_off = 2;
1689
7.74k
            }
1690
10.8k
            if (bh4 == ss_ver) {
1691
5.79k
                const enum Filter2d top_filter_2d =
1692
5.79k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
17.3k
                for (int pl = 0; pl < 2; pl++) {
1694
11.5k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
11.5k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
11.5k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
11.5k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
11.5k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
11.5k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
11.5k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
11.5k
                    if (res) return res;
1702
11.5k
                }
1703
5.79k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
5.79k
            }
1705
32.5k
            for (int pl = 0; pl < 2; pl++) {
1706
21.7k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
21.7k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
21.7k
                         refp, b->ref[0], filter_2d);
1709
21.7k
                if (res) return res;
1710
21.7k
            }
1711
191k
        } else {
1712
191k
            if (imin(cbw4, cbh4) > 1 &&
1713
100k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
97.1k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
6.37k
            {
1716
19.1k
                for (int pl = 0; pl < 2; pl++) {
1717
12.7k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
12.7k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
12.7k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
12.7k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
12.7k
                    if (res) return res;
1722
12.7k
                }
1723
184k
            } else {
1724
553k
                for (int pl = 0; pl < 2; pl++) {
1725
369k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
369k
                             NULL, f->cur.stride[1],
1727
369k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
369k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
369k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
369k
                    if (res) return res;
1731
369k
                    if (b->motion_mode == MM_OBMC) {
1732
77.3k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
77.3k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
77.3k
                        if (res) return res;
1735
77.3k
                    }
1736
369k
                }
1737
184k
            }
1738
191k
            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
10.2k
                        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
3.05k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
3.05k
                        const int sby = t->by >> f->sb_shift;
1756
3.05k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
3.05k
                    }
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
191k
        }
1778
1779
237k
    skip_inter_chroma_pred: {}
1780
237k
        t->tl_4x4_filter = filter_2d;
1781
237k
    } else {
1782
76.5k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
76.5k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
76.5k
        int jnt_weight;
1786
76.5k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
76.5k
        const uint8_t *mask;
1788
1789
229k
        for (int i = 0; i < 2; i++) {
1790
153k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
153k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
4.74k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
4.74k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
4.74k
                if (res) return res;
1796
148k
            } else {
1797
148k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
148k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
148k
                if (res) return res;
1800
148k
            }
1801
153k
        }
1802
76.5k
        switch (b->comp_type) {
1803
47.3k
        case COMP_INTER_AVG:
1804
47.3k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
47.3k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
47.3k
            break;
1807
8.87k
        case COMP_INTER_WEIGHTED_AVG:
1808
8.87k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
8.87k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
8.87k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
8.87k
            break;
1812
13.3k
        case COMP_INTER_SEG:
1813
13.3k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
13.3k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
13.3k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
13.3k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
13.3k
            mask = seg_mask;
1818
13.3k
            break;
1819
6.97k
        case COMP_INTER_WEDGE:
1820
6.97k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
6.97k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
6.97k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
6.97k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
6.97k
            if (has_chroma)
1825
6.48k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
6.97k
            break;
1827
76.5k
        }
1828
1829
        // chroma
1830
217k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
435k
            for (int i = 0; i < 2; i++) {
1832
290k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
290k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
37.0k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
3.65k
                {
1836
3.65k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
3.65k
                                      b_dim, 1 + pl,
1838
3.65k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
3.65k
                    if (res) return res;
1840
286k
                } else {
1841
286k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
286k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
286k
                    if (res) return res;
1844
286k
                }
1845
290k
            }
1846
145k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
145k
            switch (b->comp_type) {
1848
90.4k
            case COMP_INTER_AVG:
1849
90.4k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
90.4k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
90.4k
                            HIGHBD_CALL_SUFFIX);
1852
90.4k
                break;
1853
15.9k
            case COMP_INTER_WEIGHTED_AVG:
1854
15.9k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
15.9k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
15.9k
                              HIGHBD_CALL_SUFFIX);
1857
15.9k
                break;
1858
12.9k
            case COMP_INTER_WEDGE:
1859
38.8k
            case COMP_INTER_SEG:
1860
38.8k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
38.8k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
38.8k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
38.8k
                             HIGHBD_CALL_SUFFIX);
1864
38.8k
                break;
1865
145k
            }
1866
145k
        }
1867
76.5k
    }
1868
1869
389k
    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
389k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
389k
    if (b->skip) {
1882
        // reset coef contexts
1883
99.7k
        BlockContext *const a = t->a;
1884
99.7k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
99.7k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
99.7k
        if (has_chroma) {
1887
71.0k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
71.0k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
71.0k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
71.0k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
71.0k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
71.0k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
71.0k
        }
1894
99.7k
        return 0;
1895
99.7k
    }
1896
1897
289k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
289k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
289k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
593k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
611k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
307k
            int y_off = !!init_y, y;
1905
307k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
631k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
323k
                 y += ytx->h, y_off++)
1908
323k
            {
1909
323k
                int x, x_off = !!init_x;
1910
711k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
387k
                     x += ytx->w, x_off++)
1912
387k
                {
1913
387k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
387k
                                   x_off, y_off, &dst[x * 4]);
1915
387k
                    t->bx += ytx->w;
1916
387k
                }
1917
323k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
323k
                t->bx -= x;
1919
323k
                t->by += ytx->h;
1920
323k
            }
1921
307k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
307k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
813k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
542k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
542k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
542k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
1.13M
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
589k
                {
1931
589k
                    int x;
1932
589k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
1.32M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
739k
                    {
1935
739k
                        coef *cf;
1936
739k
                        int eob;
1937
739k
                        enum TxfmType txtp;
1938
739k
                        if (t->frame_thread.pass) {
1939
739k
                            const int p = t->frame_thread.pass & 1;
1940
739k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
739k
                            cf = ts->frame_thread[p].cf;
1942
739k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
739k
                            eob  = cbi >> 5;
1944
739k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            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
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
739k
                        if (eob >= 0) {
1964
219k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
219k
                            dsp->itx.itxfm_add[b->uvtx]
1967
219k
                                              [txtp](&uvdst[4 * x],
1968
219k
                                                     f->cur.stride[1],
1969
219k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
219k
                            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
219k
                        }
1974
739k
                        t->bx += uvtx->w << ss_hor;
1975
739k
                    }
1976
589k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
589k
                    t->bx -= x << ss_hor;
1978
589k
                    t->by += uvtx->h << ss_ver;
1979
589k
                }
1980
542k
                t->by -= y << ss_ver;
1981
542k
            }
1982
307k
        }
1983
303k
    }
1984
289k
    return 0;
1985
389k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
186k
{
1560
186k
    Dav1dTileState *const ts = t->ts;
1561
186k
    const Dav1dFrameContext *const f = t->f;
1562
186k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
186k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
186k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
186k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
186k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
186k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
186k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
186k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
186k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
158k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
149k
                           (bh4 > ss_ver || t->by & 1);
1573
186k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
186k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
186k
    int res;
1576
1577
    // prediction
1578
186k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
186k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
186k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
186k
    const ptrdiff_t uvdstoff =
1582
186k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
186k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
48.8k
        assert(!f->frame_hdr->super_res.enabled);
1586
48.8k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
48.8k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
48.8k
        if (res) return res;
1589
84.6k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
56.4k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
56.4k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
56.4k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
56.4k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
56.4k
            if (res) return res;
1595
56.4k
        }
1596
137k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
105k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
105k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
105k
        if (imin(bw4, bh4) > 1 &&
1601
55.6k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
53.8k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.36k
        {
1604
2.36k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.36k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.36k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.36k
            if (res) return res;
1608
103k
        } else {
1609
103k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
103k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
103k
            if (res) return res;
1612
103k
            if (b->motion_mode == MM_OBMC) {
1613
14.9k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
14.9k
                if (res) return res;
1615
14.9k
            }
1616
103k
        }
1617
105k
        if (b->interintra_type) {
1618
3.21k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
3.21k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
2.50k
                                   SMOOTH_PRED : b->interintra_mode;
1621
3.21k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
3.21k
            int angle = 0;
1623
3.21k
            const pixel *top_sb_edge = NULL;
1624
3.21k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.02k
                top_sb_edge = f->ipred_edge[0];
1626
1.02k
                const int sby = t->by >> f->sb_shift;
1627
1.02k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.02k
            }
1629
3.21k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
3.21k
                                                  t->by, t->by > ts->tiling.row_start,
1631
3.21k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
3.21k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
3.21k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
3.21k
                                                  HIGHBD_CALL_SUFFIX);
1635
3.21k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
3.21k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
3.21k
                                     HIGHBD_CALL_SUFFIX);
1638
3.21k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
3.21k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
3.21k
        }
1641
1642
105k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
86.6k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
86.6k
        refmvs_block *const *r;
1647
86.6k
        if (is_sub8x8) {
1648
7.22k
            assert(ss_hor == 1);
1649
7.22k
            r = &t->rt.r[(t->by & 31) + 5];
1650
7.22k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
7.22k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
7.22k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.17k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
7.22k
        }
1655
1656
        // chroma prediction
1657
86.6k
        if (is_sub8x8) {
1658
6.35k
            assert(ss_hor == 1);
1659
6.35k
            ptrdiff_t h_off = 0, v_off = 0;
1660
6.35k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
4.00k
                for (int pl = 0; pl < 2; pl++) {
1662
2.66k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
2.66k
                             NULL, f->cur.stride[1],
1664
2.66k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
2.66k
                             r[-1][t->bx - 1].mv.mv[0],
1666
2.66k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
2.66k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
2.66k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
2.66k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
2.66k
                    if (res) return res;
1671
2.66k
                }
1672
1.33k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.33k
                h_off = 2;
1674
1.33k
            }
1675
6.35k
            if (bw4 == 1) {
1676
4.50k
                const enum Filter2d left_filter_2d =
1677
4.50k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
13.5k
                for (int pl = 0; pl < 2; pl++) {
1679
9.00k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
9.00k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
9.00k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
9.00k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
9.00k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
9.00k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
9.00k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
9.00k
                    if (res) return res;
1687
9.00k
                }
1688
4.50k
                h_off = 2;
1689
4.50k
            }
1690
6.35k
            if (bh4 == ss_ver) {
1691
3.18k
                const enum Filter2d top_filter_2d =
1692
3.18k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
9.55k
                for (int pl = 0; pl < 2; pl++) {
1694
6.37k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
6.37k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
6.37k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
6.37k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
6.37k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
6.37k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
6.37k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
6.37k
                    if (res) return res;
1702
6.37k
                }
1703
3.18k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
3.18k
            }
1705
19.0k
            for (int pl = 0; pl < 2; pl++) {
1706
12.7k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
12.7k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
12.7k
                         refp, b->ref[0], filter_2d);
1709
12.7k
                if (res) return res;
1710
12.7k
            }
1711
80.3k
        } else {
1712
80.3k
            if (imin(cbw4, cbh4) > 1 &&
1713
38.7k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
37.1k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.15k
            {
1716
6.46k
                for (int pl = 0; pl < 2; pl++) {
1717
4.30k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
4.30k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
4.30k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
4.30k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
4.30k
                    if (res) return res;
1722
4.30k
                }
1723
78.1k
            } else {
1724
234k
                for (int pl = 0; pl < 2; pl++) {
1725
156k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
156k
                             NULL, f->cur.stride[1],
1727
156k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
156k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
156k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
156k
                    if (res) return res;
1731
156k
                    if (b->motion_mode == MM_OBMC) {
1732
28.2k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
28.2k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
28.2k
                        if (res) return res;
1735
28.2k
                    }
1736
156k
                }
1737
78.1k
            }
1738
80.3k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
2.77k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
8.31k
                for (int pl = 0; pl < 2; pl++) {
1745
5.54k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
5.54k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
5.54k
                    enum IntraPredMode m =
1748
5.54k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
4.58k
                        SMOOTH_PRED : b->interintra_mode;
1750
5.54k
                    int angle = 0;
1751
5.54k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
5.54k
                    const pixel *top_sb_edge = NULL;
1753
5.54k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.62k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.62k
                        const int sby = t->by >> f->sb_shift;
1756
1.62k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.62k
                    }
1758
5.54k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
5.54k
                                                          (t->bx >> ss_hor) >
1760
5.54k
                                                              (ts->tiling.col_start >> ss_hor),
1761
5.54k
                                                          t->by >> ss_ver,
1762
5.54k
                                                          (t->by >> ss_ver) >
1763
5.54k
                                                              (ts->tiling.row_start >> ss_ver),
1764
5.54k
                                                          ts->tiling.col_end >> ss_hor,
1765
5.54k
                                                          ts->tiling.row_end >> ss_ver,
1766
5.54k
                                                          0, uvdst, f->cur.stride[1],
1767
5.54k
                                                          top_sb_edge, m,
1768
5.54k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
5.54k
                                                          HIGHBD_CALL_SUFFIX);
1770
5.54k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
5.54k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
5.54k
                                             HIGHBD_CALL_SUFFIX);
1773
5.54k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
5.54k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
5.54k
                }
1776
2.77k
            }
1777
80.3k
        }
1778
1779
105k
    skip_inter_chroma_pred: {}
1780
105k
        t->tl_4x4_filter = filter_2d;
1781
105k
    } else {
1782
31.9k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
31.9k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
31.9k
        int jnt_weight;
1786
31.9k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
31.9k
        const uint8_t *mask;
1788
1789
95.8k
        for (int i = 0; i < 2; i++) {
1790
63.8k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
63.8k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.36k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.36k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.36k
                if (res) return res;
1796
61.5k
            } else {
1797
61.5k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
61.5k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
61.5k
                if (res) return res;
1800
61.5k
            }
1801
63.8k
        }
1802
31.9k
        switch (b->comp_type) {
1803
22.2k
        case COMP_INTER_AVG:
1804
22.2k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
22.2k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
22.2k
            break;
1807
1.76k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.76k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.76k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.76k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.76k
            break;
1812
4.38k
        case COMP_INTER_SEG:
1813
4.38k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
4.38k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
4.38k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
4.38k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
4.38k
            mask = seg_mask;
1818
4.38k
            break;
1819
3.57k
        case COMP_INTER_WEDGE:
1820
3.57k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
3.57k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
3.57k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
3.57k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
3.57k
            if (has_chroma)
1825
3.33k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
3.57k
            break;
1827
31.9k
        }
1828
1829
        // chroma
1830
88.6k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
177k
            for (int i = 0; i < 2; i++) {
1832
118k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
118k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
15.9k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.86k
                {
1836
1.86k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.86k
                                      b_dim, 1 + pl,
1838
1.86k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.86k
                    if (res) return res;
1840
116k
                } else {
1841
116k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
116k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
116k
                    if (res) return res;
1844
116k
                }
1845
118k
            }
1846
59.1k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
59.1k
            switch (b->comp_type) {
1848
42.0k
            case COMP_INTER_AVG:
1849
42.0k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
42.0k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
42.0k
                            HIGHBD_CALL_SUFFIX);
1852
42.0k
                break;
1853
1.85k
            case COMP_INTER_WEIGHTED_AVG:
1854
1.85k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
1.85k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
1.85k
                              HIGHBD_CALL_SUFFIX);
1857
1.85k
                break;
1858
6.66k
            case COMP_INTER_WEDGE:
1859
15.1k
            case COMP_INTER_SEG:
1860
15.1k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
15.1k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
15.1k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
15.1k
                             HIGHBD_CALL_SUFFIX);
1864
15.1k
                break;
1865
59.1k
            }
1866
59.1k
        }
1867
31.9k
    }
1868
1869
186k
    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
186k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
186k
    if (b->skip) {
1882
        // reset coef contexts
1883
50.6k
        BlockContext *const a = t->a;
1884
50.6k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
50.6k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
50.6k
        if (has_chroma) {
1887
26.7k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
26.7k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
26.7k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
26.7k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
26.7k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
26.7k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
26.7k
        }
1894
50.6k
        return 0;
1895
50.6k
    }
1896
1897
135k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
135k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
135k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
277k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
284k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
143k
            int y_off = !!init_y, y;
1905
143k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
289k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
146k
                 y += ytx->h, y_off++)
1908
146k
            {
1909
146k
                int x, x_off = !!init_x;
1910
304k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
157k
                     x += ytx->w, x_off++)
1912
157k
                {
1913
157k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
157k
                                   x_off, y_off, &dst[x * 4]);
1915
157k
                    t->bx += ytx->w;
1916
157k
                }
1917
146k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
146k
                t->bx -= x;
1919
146k
                t->by += ytx->h;
1920
146k
            }
1921
143k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
143k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
371k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
247k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
247k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
247k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
507k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
259k
                {
1931
259k
                    int x;
1932
259k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
553k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
293k
                    {
1935
293k
                        coef *cf;
1936
293k
                        int eob;
1937
293k
                        enum TxfmType txtp;
1938
293k
                        if (t->frame_thread.pass) {
1939
293k
                            const int p = t->frame_thread.pass & 1;
1940
293k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
293k
                            cf = ts->frame_thread[p].cf;
1942
293k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
293k
                            eob  = cbi >> 5;
1944
293k
                            txtp = cbi & 0x1f;
1945
293k
                        } 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
293k
                        if (eob >= 0) {
1964
73.5k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
73.5k
                            dsp->itx.itxfm_add[b->uvtx]
1967
73.5k
                                              [txtp](&uvdst[4 * x],
1968
73.5k
                                                     f->cur.stride[1],
1969
73.5k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
73.5k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
73.5k
                        }
1974
293k
                        t->bx += uvtx->w << ss_hor;
1975
293k
                    }
1976
259k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
259k
                    t->bx -= x << ss_hor;
1978
259k
                    t->by += uvtx->h << ss_ver;
1979
259k
                }
1980
247k
                t->by -= y << ss_ver;
1981
247k
            }
1982
143k
        }
1983
141k
    }
1984
135k
    return 0;
1985
186k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
202k
{
1560
202k
    Dav1dTileState *const ts = t->ts;
1561
202k
    const Dav1dFrameContext *const f = t->f;
1562
202k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
202k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
202k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
202k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
202k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
202k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
202k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
202k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
202k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
191k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
185k
                           (bh4 > ss_ver || t->by & 1);
1573
202k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
202k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
202k
    int res;
1576
1577
    // prediction
1578
202k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
202k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
202k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
202k
    const ptrdiff_t uvdstoff =
1582
202k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
202k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
26.2k
        assert(!f->frame_hdr->super_res.enabled);
1586
26.2k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
26.2k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
26.2k
        if (res) return res;
1589
71.6k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
47.7k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
47.7k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
47.7k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
47.7k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
47.7k
            if (res) return res;
1595
47.7k
        }
1596
176k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
131k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
131k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
131k
        if (imin(bw4, bh4) > 1 &&
1601
77.1k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
75.7k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
4.32k
        {
1604
4.32k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
4.32k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
4.32k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
4.32k
            if (res) return res;
1608
127k
        } else {
1609
127k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
127k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
127k
            if (res) return res;
1612
127k
            if (b->motion_mode == MM_OBMC) {
1613
25.2k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
25.2k
                if (res) return res;
1615
25.2k
            }
1616
127k
        }
1617
131k
        if (b->interintra_type) {
1618
4.48k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
4.48k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
3.66k
                                   SMOOTH_PRED : b->interintra_mode;
1621
4.48k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
4.48k
            int angle = 0;
1623
4.48k
            const pixel *top_sb_edge = NULL;
1624
4.48k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.68k
                top_sb_edge = f->ipred_edge[0];
1626
1.68k
                const int sby = t->by >> f->sb_shift;
1627
1.68k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.68k
            }
1629
4.48k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
4.48k
                                                  t->by, t->by > ts->tiling.row_start,
1631
4.48k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
4.48k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
4.48k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
4.48k
                                                  HIGHBD_CALL_SUFFIX);
1635
4.48k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
4.48k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
4.48k
                                     HIGHBD_CALL_SUFFIX);
1638
4.48k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
4.48k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
4.48k
        }
1641
1642
131k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
115k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
115k
        refmvs_block *const *r;
1647
115k
        if (is_sub8x8) {
1648
4.79k
            assert(ss_hor == 1);
1649
4.79k
            r = &t->rt.r[(t->by & 31) + 5];
1650
4.79k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
4.79k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
4.79k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.59k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
4.79k
        }
1655
1656
        // chroma prediction
1657
115k
        if (is_sub8x8) {
1658
4.50k
            assert(ss_hor == 1);
1659
4.50k
            ptrdiff_t h_off = 0, v_off = 0;
1660
4.50k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
4.03k
                for (int pl = 0; pl < 2; pl++) {
1662
2.69k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
2.69k
                             NULL, f->cur.stride[1],
1664
2.69k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
2.69k
                             r[-1][t->bx - 1].mv.mv[0],
1666
2.69k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
2.69k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
2.69k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
2.69k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
2.69k
                    if (res) return res;
1671
2.69k
                }
1672
1.34k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.34k
                h_off = 2;
1674
1.34k
            }
1675
4.50k
            if (bw4 == 1) {
1676
3.24k
                const enum Filter2d left_filter_2d =
1677
3.24k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
9.72k
                for (int pl = 0; pl < 2; pl++) {
1679
6.48k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
6.48k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
6.48k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
6.48k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
6.48k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
6.48k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
6.48k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
6.48k
                    if (res) return res;
1687
6.48k
                }
1688
3.24k
                h_off = 2;
1689
3.24k
            }
1690
4.50k
            if (bh4 == ss_ver) {
1691
2.61k
                const enum Filter2d top_filter_2d =
1692
2.61k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
7.83k
                for (int pl = 0; pl < 2; pl++) {
1694
5.22k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
5.22k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
5.22k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
5.22k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
5.22k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
5.22k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
5.22k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
5.22k
                    if (res) return res;
1702
5.22k
                }
1703
2.61k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
2.61k
            }
1705
13.5k
            for (int pl = 0; pl < 2; pl++) {
1706
9.01k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
9.01k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
9.01k
                         refp, b->ref[0], filter_2d);
1709
9.01k
                if (res) return res;
1710
9.01k
            }
1711
110k
        } else {
1712
110k
            if (imin(cbw4, cbh4) > 1 &&
1713
61.3k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
60.0k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
4.22k
            {
1716
12.6k
                for (int pl = 0; pl < 2; pl++) {
1717
8.43k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
8.43k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
8.43k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
8.43k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
8.43k
                    if (res) return res;
1722
8.43k
                }
1723
106k
            } else {
1724
319k
                for (int pl = 0; pl < 2; pl++) {
1725
212k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
212k
                             NULL, f->cur.stride[1],
1727
212k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
212k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
212k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
212k
                    if (res) return res;
1731
212k
                    if (b->motion_mode == MM_OBMC) {
1732
49.1k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
49.1k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
49.1k
                        if (res) return res;
1735
49.1k
                    }
1736
212k
                }
1737
106k
            }
1738
110k
            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.45k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
10.3k
                for (int pl = 0; pl < 2; pl++) {
1745
6.91k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
6.91k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
6.91k
                    enum IntraPredMode m =
1748
6.91k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
5.71k
                        SMOOTH_PRED : b->interintra_mode;
1750
6.91k
                    int angle = 0;
1751
6.91k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
6.91k
                    const pixel *top_sb_edge = NULL;
1753
6.91k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.43k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.43k
                        const int sby = t->by >> f->sb_shift;
1756
1.43k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.43k
                    }
1758
6.91k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
6.91k
                                                          (t->bx >> ss_hor) >
1760
6.91k
                                                              (ts->tiling.col_start >> ss_hor),
1761
6.91k
                                                          t->by >> ss_ver,
1762
6.91k
                                                          (t->by >> ss_ver) >
1763
6.91k
                                                              (ts->tiling.row_start >> ss_ver),
1764
6.91k
                                                          ts->tiling.col_end >> ss_hor,
1765
6.91k
                                                          ts->tiling.row_end >> ss_ver,
1766
6.91k
                                                          0, uvdst, f->cur.stride[1],
1767
6.91k
                                                          top_sb_edge, m,
1768
6.91k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
6.91k
                                                          HIGHBD_CALL_SUFFIX);
1770
6.91k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
6.91k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
6.91k
                                             HIGHBD_CALL_SUFFIX);
1773
6.91k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
6.91k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
6.91k
                }
1776
3.45k
            }
1777
110k
        }
1778
1779
131k
    skip_inter_chroma_pred: {}
1780
131k
        t->tl_4x4_filter = filter_2d;
1781
131k
    } else {
1782
44.6k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
44.6k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
44.6k
        int jnt_weight;
1786
44.6k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
44.6k
        const uint8_t *mask;
1788
1789
133k
        for (int i = 0; i < 2; i++) {
1790
89.3k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
89.3k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.38k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.38k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.38k
                if (res) return res;
1796
86.9k
            } else {
1797
86.9k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
86.9k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
86.9k
                if (res) return res;
1800
86.9k
            }
1801
89.3k
        }
1802
44.6k
        switch (b->comp_type) {
1803
25.1k
        case COMP_INTER_AVG:
1804
25.1k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
25.1k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
25.1k
            break;
1807
7.11k
        case COMP_INTER_WEIGHTED_AVG:
1808
7.11k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
7.11k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
7.11k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
7.11k
            break;
1812
8.98k
        case COMP_INTER_SEG:
1813
8.98k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
8.98k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
8.98k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
8.98k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
8.98k
            mask = seg_mask;
1818
8.98k
            break;
1819
3.39k
        case COMP_INTER_WEDGE:
1820
3.39k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
3.39k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
3.39k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
3.39k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
3.39k
            if (has_chroma)
1825
3.14k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
3.39k
            break;
1827
44.6k
        }
1828
1829
        // chroma
1830
129k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
258k
            for (int i = 0; i < 2; i++) {
1832
172k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
172k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
21.1k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.78k
                {
1836
1.78k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.78k
                                      b_dim, 1 + pl,
1838
1.78k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.78k
                    if (res) return res;
1840
170k
                } else {
1841
170k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
170k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
170k
                    if (res) return res;
1844
170k
                }
1845
172k
            }
1846
86.0k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
86.0k
            switch (b->comp_type) {
1848
48.3k
            case COMP_INTER_AVG:
1849
48.3k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
48.3k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
48.3k
                            HIGHBD_CALL_SUFFIX);
1852
48.3k
                break;
1853
14.1k
            case COMP_INTER_WEIGHTED_AVG:
1854
14.1k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
14.1k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
14.1k
                              HIGHBD_CALL_SUFFIX);
1857
14.1k
                break;
1858
6.29k
            case COMP_INTER_WEDGE:
1859
23.6k
            case COMP_INTER_SEG:
1860
23.6k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
23.6k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
23.6k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
23.6k
                             HIGHBD_CALL_SUFFIX);
1864
23.6k
                break;
1865
86.0k
            }
1866
86.0k
        }
1867
44.6k
    }
1868
1869
202k
    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
202k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
202k
    if (b->skip) {
1882
        // reset coef contexts
1883
49.1k
        BlockContext *const a = t->a;
1884
49.1k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
49.1k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
49.1k
        if (has_chroma) {
1887
44.3k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
44.3k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
44.3k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
44.3k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
44.3k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
44.3k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
44.3k
        }
1894
49.1k
        return 0;
1895
49.1k
    }
1896
1897
153k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
153k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
153k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
316k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
327k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
164k
            int y_off = !!init_y, y;
1905
164k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
341k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
177k
                 y += ytx->h, y_off++)
1908
177k
            {
1909
177k
                int x, x_off = !!init_x;
1910
406k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
229k
                     x += ytx->w, x_off++)
1912
229k
                {
1913
229k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
229k
                                   x_off, y_off, &dst[x * 4]);
1915
229k
                    t->bx += ytx->w;
1916
229k
                }
1917
177k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
177k
                t->bx -= x;
1919
177k
                t->by += ytx->h;
1920
177k
            }
1921
164k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
164k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
442k
            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
625k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
329k
                {
1931
329k
                    int x;
1932
329k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
775k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
446k
                    {
1935
446k
                        coef *cf;
1936
446k
                        int eob;
1937
446k
                        enum TxfmType txtp;
1938
446k
                        if (t->frame_thread.pass) {
1939
446k
                            const int p = t->frame_thread.pass & 1;
1940
446k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
446k
                            cf = ts->frame_thread[p].cf;
1942
446k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
446k
                            eob  = cbi >> 5;
1944
446k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            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
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
446k
                        if (eob >= 0) {
1964
146k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
146k
                            dsp->itx.itxfm_add[b->uvtx]
1967
146k
                                              [txtp](&uvdst[4 * x],
1968
146k
                                                     f->cur.stride[1],
1969
146k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
146k
                            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
146k
                        }
1974
446k
                        t->bx += uvtx->w << ss_hor;
1975
446k
                    }
1976
329k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
329k
                    t->bx -= x << ss_hor;
1978
329k
                    t->by += uvtx->h << ss_ver;
1979
329k
                }
1980
295k
                t->by -= y << ss_ver;
1981
295k
            }
1982
164k
        }
1983
162k
    }
1984
153k
    return 0;
1985
202k
}
1986
1987
130k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
130k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
130k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
130k
    const int y = sby * f->sb_step * 4;
1994
130k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
130k
    pixel *const p[3] = {
1996
130k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
130k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
130k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
130k
    };
2000
130k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
130k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
130k
                                        f->lf.start_of_tile_row[sby]);
2003
130k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
63.4k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
63.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
63.4k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
63.4k
    const int y = sby * f->sb_step * 4;
1994
63.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
63.4k
    pixel *const p[3] = {
1996
63.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
63.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
63.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
63.4k
    };
2000
63.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
63.4k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
63.4k
                                        f->lf.start_of_tile_row[sby]);
2003
63.4k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
67.1k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
67.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
67.1k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
67.1k
    const int y = sby * f->sb_step * 4;
1994
67.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
67.1k
    pixel *const p[3] = {
1996
67.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
67.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
67.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
67.1k
    };
2000
67.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
67.1k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
67.1k
                                        f->lf.start_of_tile_row[sby]);
2003
67.1k
}
2004
2005
145k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
145k
    const int y = sby * f->sb_step * 4;
2007
145k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
145k
    pixel *const p[3] = {
2009
145k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
145k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
145k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
145k
    };
2013
145k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
145k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
145k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
130k
    {
2017
130k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
130k
    }
2019
145k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
124k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
124k
    }
2023
145k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
71.1k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
71.1k
    const int y = sby * f->sb_step * 4;
2007
71.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
71.1k
    pixel *const p[3] = {
2009
71.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
71.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
71.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
71.1k
    };
2013
71.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
71.1k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
71.1k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
63.4k
    {
2017
63.4k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
63.4k
    }
2019
71.1k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
59.0k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
59.0k
    }
2023
71.1k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
74.7k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
74.7k
    const int y = sby * f->sb_step * 4;
2007
74.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
74.7k
    pixel *const p[3] = {
2009
74.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
74.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
74.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
74.7k
    };
2013
74.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
74.7k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
74.7k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
67.1k
    {
2017
67.1k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
67.1k
    }
2019
74.7k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
65.2k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
65.2k
    }
2023
74.7k
}
2024
2025
75.3k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
75.3k
    const Dav1dFrameContext *const f = tc->f;
2027
75.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
75.3k
    const int sbsz = f->sb_step;
2029
75.3k
    const int y = sby * sbsz * 4;
2030
75.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
75.3k
    pixel *const p[3] = {
2032
75.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
75.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
75.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
75.3k
    };
2036
75.3k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
75.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
75.3k
    const int start = sby * sbsz;
2039
75.3k
    if (sby) {
2040
33.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
33.6k
        pixel *p_up[3] = {
2042
33.6k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
33.6k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
33.6k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
33.6k
        };
2046
33.6k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
33.6k
    }
2048
75.3k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
75.3k
    const int end = imin(start + n_blks, f->bh);
2050
75.3k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
75.3k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
36.5k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
36.5k
    const Dav1dFrameContext *const f = tc->f;
2027
36.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
36.5k
    const int sbsz = f->sb_step;
2029
36.5k
    const int y = sby * sbsz * 4;
2030
36.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
36.5k
    pixel *const p[3] = {
2032
36.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
36.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
36.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
36.5k
    };
2036
36.5k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
36.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
36.5k
    const int start = sby * sbsz;
2039
36.5k
    if (sby) {
2040
16.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
16.8k
        pixel *p_up[3] = {
2042
16.8k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
16.8k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
16.8k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
16.8k
        };
2046
16.8k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
16.8k
    }
2048
36.5k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
36.5k
    const int end = imin(start + n_blks, f->bh);
2050
36.5k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
36.5k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
38.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
38.7k
    const Dav1dFrameContext *const f = tc->f;
2027
38.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
38.7k
    const int sbsz = f->sb_step;
2029
38.7k
    const int y = sby * sbsz * 4;
2030
38.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
38.7k
    pixel *const p[3] = {
2032
38.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
38.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
38.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
38.7k
    };
2036
38.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
38.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
38.7k
    const int start = sby * sbsz;
2039
38.7k
    if (sby) {
2040
16.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
16.7k
        pixel *p_up[3] = {
2042
16.7k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
16.7k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
16.7k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
16.7k
        };
2046
16.7k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
16.7k
    }
2048
38.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
38.7k
    const int end = imin(start + n_blks, f->bh);
2050
38.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
38.7k
}
2052
2053
13.0k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
13.0k
    const int sbsz = f->sb_step;
2055
13.0k
    const int y = sby * sbsz * 4;
2056
13.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
13.0k
    const pixel *const p[3] = {
2058
13.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
13.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
13.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
13.0k
    };
2062
13.0k
    pixel *const sr_p[3] = {
2063
13.0k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
13.0k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
13.0k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
13.0k
    };
2067
13.0k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
43.3k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
30.3k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
30.3k
        const int h_start = 8 * !!sby >> ss_ver;
2071
30.3k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
30.3k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
30.3k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
30.3k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
30.3k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
30.3k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
30.3k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
30.3k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
30.3k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
30.3k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
30.3k
                          imin(img_h, h_end) + h_start, src_w,
2083
30.3k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
30.3k
                          HIGHBD_CALL_SUFFIX);
2085
30.3k
    }
2086
13.0k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
6.27k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
6.27k
    const int sbsz = f->sb_step;
2055
6.27k
    const int y = sby * sbsz * 4;
2056
6.27k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
6.27k
    const pixel *const p[3] = {
2058
6.27k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
6.27k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
6.27k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
6.27k
    };
2062
6.27k
    pixel *const sr_p[3] = {
2063
6.27k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
6.27k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
6.27k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
6.27k
    };
2067
6.27k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
19.3k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
13.1k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
13.1k
        const int h_start = 8 * !!sby >> ss_ver;
2071
13.1k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
13.1k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
13.1k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
13.1k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
13.1k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
13.1k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
13.1k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
13.1k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
13.1k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
13.1k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
13.1k
                          imin(img_h, h_end) + h_start, src_w,
2083
13.1k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
13.1k
                          HIGHBD_CALL_SUFFIX);
2085
13.1k
    }
2086
6.27k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
6.78k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
6.78k
    const int sbsz = f->sb_step;
2055
6.78k
    const int y = sby * sbsz * 4;
2056
6.78k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
6.78k
    const pixel *const p[3] = {
2058
6.78k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
6.78k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
6.78k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
6.78k
    };
2062
6.78k
    pixel *const sr_p[3] = {
2063
6.78k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
6.78k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
6.78k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
6.78k
    };
2067
6.78k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
23.9k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
17.1k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
17.1k
        const int h_start = 8 * !!sby >> ss_ver;
2071
17.1k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
17.1k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
17.1k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
17.1k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
17.1k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
17.1k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
17.1k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
17.1k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
17.1k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
17.1k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
17.1k
                          imin(img_h, h_end) + h_start, src_w,
2083
17.1k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
17.1k
                          HIGHBD_CALL_SUFFIX);
2085
17.1k
    }
2086
6.78k
}
2087
2088
95.0k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
95.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
95.0k
    const int y = sby * f->sb_step * 4;
2091
95.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
95.0k
    pixel *const sr_p[3] = {
2093
95.0k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
95.0k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
95.0k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
95.0k
    };
2097
95.0k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
95.0k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
45.3k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
45.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
45.3k
    const int y = sby * f->sb_step * 4;
2091
45.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
45.3k
    pixel *const sr_p[3] = {
2093
45.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
45.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
45.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
45.3k
    };
2097
45.3k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
45.3k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
49.6k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
49.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
49.6k
    const int y = sby * f->sb_step * 4;
2091
49.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
49.6k
    pixel *const sr_p[3] = {
2093
49.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
49.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
49.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
49.6k
    };
2097
49.6k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
49.6k
}
2099
2100
0
void bytefn(dav1d_filter_sbrow)(Dav1dFrameContext *const f, const int sby) {
2101
0
    bytefn(dav1d_filter_sbrow_deblock_cols)(f, sby);
2102
0
    bytefn(dav1d_filter_sbrow_deblock_rows)(f, sby);
2103
0
    if (f->seq_hdr->cdef)
2104
0
        bytefn(dav1d_filter_sbrow_cdef)(f->c->tc, sby);
2105
0
    if (f->frame_hdr->width[0] != f->frame_hdr->width[1])
2106
0
        bytefn(dav1d_filter_sbrow_resize)(f, sby);
2107
0
    if (f->lf.restore_planes)
2108
0
        bytefn(dav1d_filter_sbrow_lr)(f, sby);
2109
0
}
Unexecuted instantiation: dav1d_filter_sbrow_8bpc
Unexecuted instantiation: dav1d_filter_sbrow_16bpc
2110
2111
165k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
165k
    const Dav1dFrameContext *const f = t->f;
2113
165k
    Dav1dTileState *const ts = t->ts;
2114
165k
    const int sby = t->by >> f->sb_shift;
2115
165k
    const int sby_off = f->sb128w * 128 * sby;
2116
165k
    const int x_off = ts->tiling.col_start;
2117
2118
165k
    const pixel *const y =
2119
165k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
165k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
165k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
165k
               4 * (ts->tiling.col_end - x_off));
2123
2124
165k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
133k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
133k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
133k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
133k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
400k
        for (int pl = 1; pl <= 2; pl++)
2131
267k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
125k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
125k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
133k
    }
2135
165k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
80.3k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
80.3k
    const Dav1dFrameContext *const f = t->f;
2113
80.3k
    Dav1dTileState *const ts = t->ts;
2114
80.3k
    const int sby = t->by >> f->sb_shift;
2115
80.3k
    const int sby_off = f->sb128w * 128 * sby;
2116
80.3k
    const int x_off = ts->tiling.col_start;
2117
2118
80.3k
    const pixel *const y =
2119
80.3k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
80.3k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
80.3k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
80.3k
               4 * (ts->tiling.col_end - x_off));
2123
2124
80.3k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
62.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
62.6k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
62.6k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
62.6k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
187k
        for (int pl = 1; pl <= 2; pl++)
2131
125k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
125k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
125k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
62.6k
    }
2135
80.3k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
85.2k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
85.2k
    const Dav1dFrameContext *const f = t->f;
2113
85.2k
    Dav1dTileState *const ts = t->ts;
2114
85.2k
    const int sby = t->by >> f->sb_shift;
2115
85.2k
    const int sby_off = f->sb128w * 128 * sby;
2116
85.2k
    const int x_off = ts->tiling.col_start;
2117
2118
85.2k
    const pixel *const y =
2119
85.2k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
85.2k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
85.2k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
85.2k
               4 * (ts->tiling.col_end - x_off));
2123
2124
85.2k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
70.9k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
70.9k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
70.9k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
70.9k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
212k
        for (int pl = 1; pl <= 2; pl++)
2131
141k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
70.9k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
70.9k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
70.9k
    }
2135
85.2k
}
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
24.9k
{
2142
24.9k
    const Dav1dFrameContext *const f = t->f;
2143
24.9k
    pixel *const pal = t->frame_thread.pass ?
2144
24.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
24.9k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
24.9k
        bytefn(t->scratch.pal)[0];
2147
118k
    for (int x = 0; x < bw4; x++)
2148
93.7k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
98.5k
    for (int y = 0; y < bh4; y++)
2150
73.6k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
24.9k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
11.6k
{
2142
11.6k
    const Dav1dFrameContext *const f = t->f;
2143
11.6k
    pixel *const pal = t->frame_thread.pass ?
2144
11.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
11.6k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
11.6k
        bytefn(t->scratch.pal)[0];
2147
52.6k
    for (int x = 0; x < bw4; x++)
2148
41.0k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
44.0k
    for (int y = 0; y < bh4; y++)
2150
32.4k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
11.6k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
13.2k
{
2142
13.2k
    const Dav1dFrameContext *const f = t->f;
2143
13.2k
    pixel *const pal = t->frame_thread.pass ?
2144
13.2k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
13.2k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
13.2k
        bytefn(t->scratch.pal)[0];
2147
66.0k
    for (int x = 0; x < bw4; x++)
2148
52.7k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
54.5k
    for (int y = 0; y < bh4; y++)
2150
41.2k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
13.2k
}
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
6.68k
{
2158
6.68k
    const Dav1dFrameContext *const f = t->f;
2159
6.68k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
6.68k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
6.68k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
6.68k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
20.0k
    for (int pl = 1; pl <= 2; pl++) {
2165
77.5k
        for (int x = 0; x < bw4; x++)
2166
64.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
68.0k
        for (int y = 0; y < bh4; y++)
2168
54.6k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
13.3k
    }
2170
6.68k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
2.35k
{
2158
2.35k
    const Dav1dFrameContext *const f = t->f;
2159
2.35k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
2.35k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
2.35k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
2.35k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
7.05k
    for (int pl = 1; pl <= 2; pl++) {
2165
27.7k
        for (int x = 0; x < bw4; x++)
2166
23.0k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
24.3k
        for (int y = 0; y < bh4; y++)
2168
19.6k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
4.70k
    }
2170
2.35k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
4.33k
{
2158
4.33k
    const Dav1dFrameContext *const f = t->f;
2159
4.33k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
4.33k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
4.33k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
4.33k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
13.0k
    for (int pl = 1; pl <= 2; pl++) {
2165
49.7k
        for (int x = 0; x < bw4; x++)
2166
41.0k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
43.7k
        for (int y = 0; y < bh4; y++)
2168
35.0k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
8.67k
    }
2170
4.33k
}
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
31.6k
{
2176
31.6k
    Dav1dTileState *const ts = t->ts;
2177
31.6k
    const Dav1dFrameContext *const f = t->f;
2178
31.6k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
31.6k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
31.6k
    pixel cache[16], used_cache[8];
2181
31.6k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
31.6k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
31.6k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
31.6k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
31.6k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
57.5k
    while (l_cache && a_cache) {
2190
25.9k
        if (*l < *a) {
2191
9.98k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
9.91k
                cache[n_cache++] = *l;
2193
9.98k
            l++;
2194
9.98k
            l_cache--;
2195
15.9k
        } else {
2196
15.9k
            if (*a == *l) {
2197
5.95k
                l++;
2198
5.95k
                l_cache--;
2199
5.95k
            }
2200
15.9k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
15.4k
                cache[n_cache++] = *a;
2202
15.9k
            a++;
2203
15.9k
            a_cache--;
2204
15.9k
        }
2205
25.9k
    }
2206
31.6k
    if (l_cache) {
2207
39.8k
        do {
2208
39.8k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
32.5k
                cache[n_cache++] = *l;
2210
39.8k
            l++;
2211
39.8k
        } while (--l_cache > 0);
2212
22.0k
    } else if (a_cache) {
2213
30.6k
        do {
2214
30.6k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
24.7k
                cache[n_cache++] = *a;
2216
30.6k
            a++;
2217
30.6k
        } while (--a_cache > 0);
2218
7.44k
    }
2219
2220
    // find reused cache entries
2221
31.6k
    int i = 0;
2222
104k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
72.5k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
35.4k
            used_cache[i++] = cache[n];
2225
31.6k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
31.6k
    pixel *const pal = t->frame_thread.pass ?
2229
31.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
31.6k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
31.6k
        bytefn(t->scratch.pal)[pl];
2232
31.6k
    if (i < pal_sz) {
2233
27.1k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
27.1k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
27.1k
        if (i < pal_sz) {
2237
24.4k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
24.4k
            const int max = (1 << bpc) - 1;
2239
2240
58.3k
            do {
2241
58.3k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
58.3k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
58.3k
                if (prev + !pl >= max) {
2244
32.9k
                    for (; i < pal_sz; i++)
2245
21.4k
                        pal[i] = max;
2246
11.4k
                    break;
2247
11.4k
                }
2248
46.8k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
46.8k
            } while (i < pal_sz);
2250
24.4k
        }
2251
2252
        // merge cache+new entries
2253
27.1k
        int n = 0, m = n_used_cache;
2254
157k
        for (i = 0; i < pal_sz; i++) {
2255
130k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
23.5k
                pal[i] = used_cache[n++];
2257
106k
            } else {
2258
106k
                assert(m < pal_sz);
2259
106k
                pal[i] = pal[m++];
2260
106k
            }
2261
130k
        }
2262
27.1k
    } else {
2263
4.42k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
4.42k
    }
2265
2266
31.6k
    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
31.6k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
13.9k
{
2176
13.9k
    Dav1dTileState *const ts = t->ts;
2177
13.9k
    const Dav1dFrameContext *const f = t->f;
2178
13.9k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
13.9k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
13.9k
    pixel cache[16], used_cache[8];
2181
13.9k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
13.9k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
13.9k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
13.9k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
13.9k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
23.4k
    while (l_cache && a_cache) {
2190
9.49k
        if (*l < *a) {
2191
3.63k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
3.58k
                cache[n_cache++] = *l;
2193
3.63k
            l++;
2194
3.63k
            l_cache--;
2195
5.86k
        } else {
2196
5.86k
            if (*a == *l) {
2197
2.24k
                l++;
2198
2.24k
                l_cache--;
2199
2.24k
            }
2200
5.86k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
5.59k
                cache[n_cache++] = *a;
2202
5.86k
            a++;
2203
5.86k
            a_cache--;
2204
5.86k
        }
2205
9.49k
    }
2206
13.9k
    if (l_cache) {
2207
16.5k
        do {
2208
16.5k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
13.1k
                cache[n_cache++] = *l;
2210
16.5k
            l++;
2211
16.5k
        } while (--l_cache > 0);
2212
10.0k
    } else if (a_cache) {
2213
13.4k
        do {
2214
13.4k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
10.6k
                cache[n_cache++] = *a;
2216
13.4k
            a++;
2217
13.4k
        } while (--a_cache > 0);
2218
3.24k
    }
2219
2220
    // find reused cache entries
2221
13.9k
    int i = 0;
2222
43.2k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
29.3k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
14.2k
            used_cache[i++] = cache[n];
2225
13.9k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
13.9k
    pixel *const pal = t->frame_thread.pass ?
2229
13.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
13.9k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
13.9k
        bytefn(t->scratch.pal)[pl];
2232
13.9k
    if (i < pal_sz) {
2233
12.2k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
12.2k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
12.2k
        if (i < pal_sz) {
2237
11.0k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
11.0k
            const int max = (1 << bpc) - 1;
2239
2240
26.5k
            do {
2241
26.5k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
26.5k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
26.5k
                if (prev + !pl >= max) {
2244
16.0k
                    for (; i < pal_sz; i++)
2245
10.6k
                        pal[i] = max;
2246
5.40k
                    break;
2247
5.40k
                }
2248
21.1k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
21.1k
            } while (i < pal_sz);
2250
11.0k
        }
2251
2252
        // merge cache+new entries
2253
12.2k
        int n = 0, m = n_used_cache;
2254
71.3k
        for (i = 0; i < pal_sz; i++) {
2255
59.0k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
9.65k
                pal[i] = used_cache[n++];
2257
49.4k
            } else {
2258
49.4k
                assert(m < pal_sz);
2259
49.4k
                pal[i] = pal[m++];
2260
49.4k
            }
2261
59.0k
        }
2262
12.2k
    } else {
2263
1.71k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.71k
    }
2265
2266
13.9k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
13.9k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
17.6k
{
2176
17.6k
    Dav1dTileState *const ts = t->ts;
2177
17.6k
    const Dav1dFrameContext *const f = t->f;
2178
17.6k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
17.6k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
17.6k
    pixel cache[16], used_cache[8];
2181
17.6k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
17.6k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
17.6k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
17.6k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
17.6k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
34.0k
    while (l_cache && a_cache) {
2190
16.4k
        if (*l < *a) {
2191
6.34k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
6.32k
                cache[n_cache++] = *l;
2193
6.34k
            l++;
2194
6.34k
            l_cache--;
2195
10.0k
        } else {
2196
10.0k
            if (*a == *l) {
2197
3.70k
                l++;
2198
3.70k
                l_cache--;
2199
3.70k
            }
2200
10.0k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
9.84k
                cache[n_cache++] = *a;
2202
10.0k
            a++;
2203
10.0k
            a_cache--;
2204
10.0k
        }
2205
16.4k
    }
2206
17.6k
    if (l_cache) {
2207
23.2k
        do {
2208
23.2k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
19.3k
                cache[n_cache++] = *l;
2210
23.2k
            l++;
2211
23.2k
        } while (--l_cache > 0);
2212
11.9k
    } else if (a_cache) {
2213
17.1k
        do {
2214
17.1k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
14.0k
                cache[n_cache++] = *a;
2216
17.1k
            a++;
2217
17.1k
        } while (--a_cache > 0);
2218
4.19k
    }
2219
2220
    // find reused cache entries
2221
17.6k
    int i = 0;
2222
60.9k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
43.2k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
21.2k
            used_cache[i++] = cache[n];
2225
17.6k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
17.6k
    pixel *const pal = t->frame_thread.pass ?
2229
17.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
17.6k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
17.6k
        bytefn(t->scratch.pal)[pl];
2232
17.6k
    if (i < pal_sz) {
2233
14.9k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
14.9k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
14.9k
        if (i < pal_sz) {
2237
13.3k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
13.3k
            const int max = (1 << bpc) - 1;
2239
2240
31.8k
            do {
2241
31.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
31.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
31.8k
                if (prev + !pl >= max) {
2244
16.9k
                    for (; i < pal_sz; i++)
2245
10.8k
                        pal[i] = max;
2246
6.08k
                    break;
2247
6.08k
                }
2248
25.7k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
25.7k
            } while (i < pal_sz);
2250
13.3k
        }
2251
2252
        // merge cache+new entries
2253
14.9k
        int n = 0, m = n_used_cache;
2254
86.4k
        for (i = 0; i < pal_sz; i++) {
2255
71.4k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
13.9k
                pal[i] = used_cache[n++];
2257
57.5k
            } else {
2258
57.5k
                assert(m < pal_sz);
2259
57.5k
                pal[i] = pal[m++];
2260
57.5k
            }
2261
71.4k
        }
2262
14.9k
    } else {
2263
2.71k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
2.71k
    }
2265
2266
17.6k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
17.6k
}
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
6.68k
{
2281
6.68k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
6.68k
    Dav1dTileState *const ts = t->ts;
2285
6.68k
    const Dav1dFrameContext *const f = t->f;
2286
6.68k
    pixel *const pal = t->frame_thread.pass ?
2287
6.68k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
6.68k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
6.68k
        bytefn(t->scratch.pal)[2];
2290
6.68k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
6.68k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
3.27k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
3.27k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
3.27k
        const int max = (1 << bpc) - 1;
2295
13.9k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
10.6k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
10.6k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
10.6k
            prev = pal[i] = (prev + delta) & max;
2299
10.6k
        }
2300
3.41k
    } else {
2301
17.9k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
14.5k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.41k
    }
2304
6.68k
    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
6.68k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
2.35k
{
2281
2.35k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
2.35k
    Dav1dTileState *const ts = t->ts;
2285
2.35k
    const Dav1dFrameContext *const f = t->f;
2286
2.35k
    pixel *const pal = t->frame_thread.pass ?
2287
2.35k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
2.35k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
2.35k
        bytefn(t->scratch.pal)[2];
2290
2.35k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
2.35k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.13k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.13k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.13k
        const int max = (1 << bpc) - 1;
2295
4.73k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
3.59k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
3.59k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
3.59k
            prev = pal[i] = (prev + delta) & max;
2299
3.59k
        }
2300
1.21k
    } else {
2301
6.61k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
5.40k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.21k
    }
2304
2.35k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
2.35k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
4.33k
{
2281
4.33k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
4.33k
    Dav1dTileState *const ts = t->ts;
2285
4.33k
    const Dav1dFrameContext *const f = t->f;
2286
4.33k
    pixel *const pal = t->frame_thread.pass ?
2287
4.33k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
4.33k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
4.33k
        bytefn(t->scratch.pal)[2];
2290
4.33k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
4.33k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.13k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.13k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.13k
        const int max = (1 << bpc) - 1;
2295
9.22k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
7.08k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
7.08k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
7.08k
            prev = pal[i] = (prev + delta) & max;
2299
7.08k
        }
2300
2.20k
    } else {
2301
11.3k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
9.10k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
2.20k
    }
2304
4.33k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
4.33k
}