Coverage Report

Created: 2026-08-31 06:19

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