Coverage Report

Created: 2026-10-28 06:12

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