Coverage Report

Created: 2026-06-10 06:59

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
636k
static inline unsigned read_golomb(MsacContext *const msac) {
50
636k
    int len = 0;
51
636k
    unsigned val = 1;
52
53
1.21M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
1.21M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
636k
    return val - 1;
57
636k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
3.64M
{
66
3.64M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
3.64M
    if (chroma) {
69
1.97M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
1.97M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
1.97M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.21M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
1.97M
        unsigned ca, cl;
74
75
1.97M
#define MERGE_CTX(dir, type, no_val) \
76
3.95M
        c##dir = *(const type *) dir != no_val; \
77
3.95M
        break
78
79
1.97M
        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
792k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
400k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
245k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
541k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
1.97M
        }
91
1.97M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
890k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
350k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
200k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
538k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
1.97M
        }
98
1.97M
#undef MERGE_CTX
99
100
1.97M
        return 7 + not_one_blk * 3 + ca + cl;
101
1.97M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
655k
        return 0;
103
1.01M
    } else {
104
1.01M
        unsigned la, ll;
105
106
1.01M
#define MERGE_CTX(dir, type, tx) \
107
2.10M
        if (tx == TX_64X64) { \
108
214k
            uint64_t tmp = *(const uint64_t *) dir; \
109
214k
            tmp |= *(const uint64_t *) &dir[8]; \
110
214k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
214k
        } else \
112
2.10M
            l##dir = *(const type *) dir; \
113
2.10M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
2.10M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
2.10M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
2.10M
        break
117
118
1.01M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
486k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
209k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
234k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
15.3k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
107k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.01M
        }
126
1.05M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
496k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
203k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
234k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
15.3k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
107k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.05M
        }
134
1.05M
#undef MERGE_CTX
135
136
1.05M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.05M
    }
138
3.64M
}
139
140
static inline unsigned get_dc_sign_ctx(const int /*enum RectTxfmSize*/ tx,
141
                                       const uint8_t *const a,
142
                                       const uint8_t *const l)
143
1.52M
{
144
1.52M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
1.52M
    int s;
146
147
1.52M
#if ARCH_X86_64 && defined(__GNUC__)
148
    /* Coerce compilers into producing better code. For some reason
149
     * every x86-64 compiler is awful at handling 64-bit constants. */
150
1.52M
    __asm__("" : "+r"(mask), "+r"(mul));
151
1.52M
#endif
152
153
1.52M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
461k
    case TX_4X4: {
156
461k
        int t = *(const uint8_t *) a >> 6;
157
461k
        t    += *(const uint8_t *) l >> 6;
158
461k
        s = t - 1 - 1;
159
461k
        break;
160
0
    }
161
174k
    case TX_8X8: {
162
174k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
174k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
174k
        t *= 0x04040404U;
165
174k
        s = (int) (t >> 24) - 2 - 2;
166
174k
        break;
167
0
    }
168
168k
    case TX_16X16: {
169
168k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
168k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
168k
        t *= (uint32_t) mul;
172
168k
        s = (int) (t >> 24) - 4 - 4;
173
168k
        break;
174
0
    }
175
189k
    case TX_32X32: {
176
189k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
189k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
189k
        t *= mul;
179
189k
        s = (int) (t >> 56) - 8 - 8;
180
189k
        break;
181
0
    }
182
90.2k
    case TX_64X64: {
183
90.2k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
90.2k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
90.2k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
90.2k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
90.2k
        t *= mul;
188
90.2k
        s = (int) (t >> 56) - 16 - 16;
189
90.2k
        break;
190
0
    }
191
53.6k
    case RTX_4X8: {
192
53.6k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
53.6k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
53.6k
        t *= 0x04040404U;
195
53.6k
        s = (int) (t >> 24) - 1 - 2;
196
53.6k
        break;
197
0
    }
198
82.1k
    case RTX_8X4: {
199
82.1k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
82.1k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
82.1k
        t *= 0x04040404U;
202
82.1k
        s = (int) (t >> 24) - 2 - 1;
203
82.1k
        break;
204
0
    }
205
44.6k
    case RTX_8X16: {
206
44.6k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
44.6k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
44.6k
        t = (t >> 6) * (uint32_t) mul;
209
44.6k
        s = (int) (t >> 24) - 2 - 4;
210
44.6k
        break;
211
0
    }
212
67.5k
    case RTX_16X8: {
213
67.5k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
67.5k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
67.5k
        t = (t >> 6) * (uint32_t) mul;
216
67.5k
        s = (int) (t >> 24) - 4 - 2;
217
67.5k
        break;
218
0
    }
219
24.0k
    case RTX_16X32: {
220
24.0k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
24.0k
        t         += *(const uint64_t *) l & mask;
222
24.0k
        t = (t >> 6) * mul;
223
24.0k
        s = (int) (t >> 56) - 4 - 8;
224
24.0k
        break;
225
0
    }
226
26.7k
    case RTX_32X16: {
227
26.7k
        uint64_t t = *(const uint64_t *) a & mask;
228
26.7k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
26.7k
        t = (t >> 6) * mul;
230
26.7k
        s = (int) (t >> 56) - 8 - 4;
231
26.7k
        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
8.15k
    case RTX_64X32: {
242
8.15k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
8.15k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
8.15k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
8.15k
        t *= mul;
246
8.15k
        s = (int) (t >> 56) - 16 - 8;
247
8.15k
        break;
248
0
    }
249
25.0k
    case RTX_4X16: {
250
25.0k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
25.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
25.0k
        t = (t >> 6) * (uint32_t) mul;
253
25.0k
        s = (int) (t >> 24) - 1 - 4;
254
25.0k
        break;
255
0
    }
256
49.0k
    case RTX_16X4: {
257
49.0k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
49.0k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
49.0k
        t = (t >> 6) * (uint32_t) mul;
260
49.0k
        s = (int) (t >> 24) - 4 - 1;
261
49.0k
        break;
262
0
    }
263
15.9k
    case RTX_8X32: {
264
15.9k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
15.9k
        t         += *(const uint64_t *) l & mask;
266
15.9k
        t = (t >> 6) * mul;
267
15.9k
        s = (int) (t >> 56) - 2 - 8;
268
15.9k
        break;
269
0
    }
270
22.1k
    case RTX_32X8: {
271
22.1k
        uint64_t t = *(const uint64_t *) a & mask;
272
22.1k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
22.1k
        t = (t >> 6) * mul;
274
22.1k
        s = (int) (t >> 56) - 8 - 2;
275
22.1k
        break;
276
0
    }
277
4.50k
    case RTX_16X64: {
278
4.50k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
4.50k
        t         += *(const uint64_t *) &l[0] & mask;
280
4.50k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
4.50k
        t *= mul;
282
4.50k
        s = (int) (t >> 56) - 4 - 16;
283
4.50k
        break;
284
0
    }
285
4.19k
    case RTX_64X16: {
286
4.19k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
4.19k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
4.19k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
4.19k
        t *= mul;
290
4.19k
        s = (int) (t >> 56) - 16 - 4;
291
4.19k
        break;
292
0
    }
293
1.52M
    }
294
295
1.52M
    return (s != 0) + (s > 0);
296
1.52M
}
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
33.4M
{
305
33.4M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
33.4M
    unsigned offset;
307
33.4M
    if (tx_class == TX_CLASS_2D) {
308
31.4M
        mag += levels[1 * stride + 1];
309
31.4M
        *hi_mag = mag;
310
31.4M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
31.4M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
31.4M
    } else {
313
1.98M
        mag += levels[0 * stride + 2];
314
1.98M
        *hi_mag = mag;
315
1.98M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
1.98M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
1.98M
    }
318
33.4M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
33.4M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
3.64M
{
328
3.64M
    Dav1dTileState *const ts = t->ts;
329
3.64M
    const int chroma = !!plane;
330
3.64M
    const Dav1dFrameContext *const f = t->f;
331
3.64M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
3.64M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
3.64M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
3.64M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
3.64M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
3.64M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
3.64M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
3.64M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
3.64M
    if (all_skip) {
346
1.78M
        *res_ctx = 0x40;
347
1.78M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
1.78M
        return -1;
349
1.78M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
1.85M
    if (lossless) {
353
402k
        assert(t_dim->max == TX_4X4);
354
402k
        *txtp = WHT_WHT;
355
1.45M
    } else if (t_dim->max + intra >= TX_64X64) {
356
412k
        *txtp = DCT_DCT;
357
1.04M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
280k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
280k
                        get_uv_inter_txtp(t_dim, *txtp);
361
760k
    } 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
1.40k
        *txtp = DCT_DCT;
366
759k
    } else {
367
759k
        unsigned idx;
368
759k
        if (intra) {
369
624k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
527k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
624k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
297k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
297k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
297k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
326k
            } else {
376
326k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
326k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
326k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
326k
            }
380
624k
            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
624k
        } else {
384
135k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
38.0k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
38.0k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
38.0k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
97.4k
            } else if (t_dim->min == TX_16X16) {
389
10.0k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
10.0k
                          ts->cdf.m.txtp_inter2, 11);
391
10.0k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
87.4k
            } else {
393
87.4k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
87.4k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
87.4k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
87.4k
            }
397
135k
            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
135k
        }
401
759k
    }
402
403
    // find end-of-block (eob)
404
1.85M
    int eob;
405
1.85M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
1.85M
    const int tx2dszctx = slw + slh;
407
1.85M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
1.85M
    const int is_1d = tx_class != TX_CLASS_2D;
409
1.85M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
1.86M
    case sz: { \
412
1.86M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
1.86M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
1.86M
        break; \
415
1.86M
    }
416
572k
    case_sz(0,   16,  8, [is_1d]);
417
176k
    case_sz(1,   32,  8, [is_1d]);
418
319k
    case_sz(2,   64,  8, [is_1d]);
419
147k
    case_sz(3,  128,  8, [is_1d]);
420
257k
    case_sz(4,  256, 16, [is_1d]);
421
68.4k
    case_sz(5,  512, 16,        );
422
321k
    case_sz(6, 1024, 16,        );
423
1.85M
#undef case_sz
424
1.85M
    }
425
1.84M
    if (dbg)
426
0
        printf("Post-eob_bin_%d[%d][%d][%d]: r=%d\n",
427
0
               16 << tx2dszctx, chroma, is_1d, eob, ts->msac.rng);
428
1.84M
    if (eob > 1) {
429
1.19M
        const int eob_bin = eob - 2;
430
1.19M
        uint16_t *const eob_hi_bit_cdf =
431
1.19M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.19M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.19M
        if (dbg)
434
0
            printf("Post-eob_hi_bit[%d][%d][%d][%d]: r=%d\n",
435
0
                   t_dim->ctx, chroma, eob_bin, eob_hi_bit, ts->msac.rng);
436
1.19M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.19M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.19M
    }
440
1.84M
    assert(eob >= 0);
441
442
    // base tokens
443
1.84M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
1.84M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
1.84M
    unsigned rc, dc_tok;
446
447
1.84M
    if (eob) {
448
1.25M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.25M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.25M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.25M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.25M
        int tok = eob_tok + 1;
455
1.25M
        int level_tok = tok * 0x41;
456
1.25M
        unsigned mag;
457
458
1.25M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.25M
        unsigned x, y; \
460
1.25M
        uint8_t *level; \
461
1.25M
        if (tx_class == TX_CLASS_2D) \
462
1.25M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.25M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
87.9k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
87.9k
        else /* tx_class == TX_CLASS_V */ \
467
87.9k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.25M
        if (dbg) \
469
1.25M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
1.25M
        if (eob_tok == 2) { \
472
25.5k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
25.5k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
25.5k
            level_tok = tok + (3 << 6); \
475
25.5k
            if (dbg) \
476
25.5k
                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
25.5k
        } \
480
1.25M
        cf[rc] = tok << 11; \
481
1.25M
        if (tx_class == TX_CLASS_2D) \
482
1.25M
            level = levels + rc; \
483
1.25M
        else \
484
1.25M
            level = levels + x * stride + y; \
485
1.25M
        *level = (uint8_t) level_tok; \
486
34.6M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
33.4M
            unsigned rc_i; \
488
33.4M
            if (tx_class == TX_CLASS_2D) \
489
33.4M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
33.4M
            else if (tx_class == TX_CLASS_H) \
491
1.93M
                x = i & mask, y = i >> shift, rc_i = i; \
492
1.93M
            else /* tx_class == TX_CLASS_V */ \
493
1.93M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
33.4M
            assert(x < 32 && y < 32); \
495
33.4M
            if (tx_class == TX_CLASS_2D) \
496
33.4M
                level = levels + rc_i; \
497
33.4M
            else \
498
33.4M
                level = levels + x * stride + y; \
499
33.4M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
33.4M
            if (tx_class == TX_CLASS_2D) \
501
33.4M
                y |= x; \
502
33.4M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
33.4M
            if (dbg) \
504
33.4M
                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
33.4M
            if (tok == 3) { \
507
2.85M
                mag &= 63; \
508
2.85M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
2.85M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
2.85M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
2.85M
                if (dbg) \
512
2.85M
                    printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
513
0
                           imin(t_dim->ctx, 3), chroma, ctx, i, rc_i, tok, \
514
0
                           ts->msac.rng); \
515
2.85M
                *level = (uint8_t) (tok + (3 << 6)); \
516
2.85M
                cf[rc_i] = (tok << 11) | rc; \
517
2.85M
                rc = rc_i; \
518
30.5M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
30.5M
                tok *= 0x17ff41; \
521
30.5M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
30.5M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
30.5M
                if (tok) rc = rc_i; \
525
30.5M
                cf[rc_i] = tok; \
526
30.5M
            } \
527
33.4M
        } \
528
        /* dc */ \
529
1.25M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.25M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.25M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.25M
        if (dbg) \
533
1.25M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
1.25M
        if (dc_tok == 3) { \
536
467k
            if (tx_class == TX_CLASS_2D) \
537
467k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
457k
                      levels[1 * stride + 1]; \
539
467k
            mag &= 63; \
540
467k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
467k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
467k
            if (dbg) \
543
467k
                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
467k
        } \
546
1.25M
        break
547
548
1.25M
        const uint16_t *scan;
549
1.25M
        switch (tx_class) {
550
1.16M
        case TX_CLASS_2D: {
551
1.16M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.16M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.16M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.16M
            scan = dav1d_scans[tx];
555
1.16M
            const ptrdiff_t stride = 4 << slh;
556
1.16M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.16M
            const unsigned mask = (4 << slh) - 1;
558
1.16M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.16M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.16M
        }
561
61.5k
        case TX_CLASS_H: {
562
61.5k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
61.5k
            const ptrdiff_t stride = 16;
564
61.5k
            const unsigned shift = slh + 2, shift2 = 0;
565
61.5k
            const unsigned mask = (4 << slh) - 1;
566
61.5k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
61.5k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
61.5k
        }
569
32.1k
        case TX_CLASS_V: {
570
32.1k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
32.1k
            const ptrdiff_t stride = 16;
572
32.1k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
32.1k
            const unsigned mask = (4 << slw) - 1;
574
32.1k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
32.1k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
32.1k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.25M
        }
580
1.25M
    } else { // dc-only
581
588k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
588k
        dc_tok = 1 + tok_br;
583
588k
        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
588k
        if (tok_br == 2) {
587
22.9k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
22.9k
            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
22.9k
        }
592
588k
        rc = 0;
593
588k
    }
594
595
    // residual and sign
596
1.84M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
1.84M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
1.84M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
1.84M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
1.84M
    unsigned cul_level, dc_sign_level;
601
602
1.84M
    if (!dc_tok) {
603
321k
        cul_level = 0;
604
321k
        dc_sign_level = 1 << 6;
605
321k
        if (qm_tbl) goto ac_qm;
606
198k
        goto ac_noqm;
607
321k
    }
608
609
1.52M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
1.52M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
1.52M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
1.52M
    if (dbg)
613
0
        printf("Post-dc_sign[%d][%d][%d]: r=%d\n",
614
0
               chroma, dc_sign_ctx, dc_sign, ts->msac.rng);
615
616
1.52M
    int dc_dq = dq_tbl[0];
617
1.52M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
1.52M
    if (qm_tbl) {
620
698k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
698k
        if (dc_tok == 15) {
623
18.6k
            dc_tok = read_golomb(&ts->msac) + 15;
624
18.6k
            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
18.6k
            dc_tok &= 0xfffff;
629
18.6k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
679k
        } else {
631
679k
            dc_dq *= dc_tok;
632
679k
            assert(dc_dq <= 0xffffff);
633
679k
        }
634
698k
        cul_level = dc_tok;
635
698k
        dc_dq >>= dq_shift;
636
698k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
698k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
965k
        if (rc) ac_qm: {
640
965k
            const unsigned ac_dq = dq_tbl[1];
641
7.41M
            do {
642
7.41M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
7.41M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
7.41M
                const unsigned rc_tok = cf[rc];
646
7.41M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
7.41M
                int dq_sat;
648
649
7.41M
                if (rc_tok >= (15 << 11)) {
650
492k
                    tok = read_golomb(&ts->msac) + 15;
651
492k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
492k
                    tok &= 0xfffff;
656
492k
                    dq = (dq * tok) & 0xffffff;
657
6.92M
                } else {
658
6.92M
                    tok = rc_tok >> 11;
659
6.92M
                    dq *= tok;
660
6.92M
                    assert(dq <= 0xffffff);
661
6.92M
                }
662
7.41M
                cul_level += tok;
663
7.41M
                dq >>= dq_shift;
664
7.41M
                dq_sat = umin(dq, cf_max + sign);
665
7.41M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
7.41M
                rc = rc_tok & 0x3ff;
668
7.41M
            } while (rc);
669
965k
        }
670
828k
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
828k
        if (dc_tok == 15) {
673
30.8k
            dc_tok = read_golomb(&ts->msac) + 15;
674
30.8k
            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
30.8k
            dc_tok &= 0xfffff;
679
30.8k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
30.8k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
797k
        } else {
682
797k
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
797k
            assert(dc_dq <= cf_max);
684
797k
        }
685
828k
        cul_level = dc_tok;
686
828k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
1.25M
        if (rc) ac_noqm: {
689
1.25M
            const unsigned ac_dq = dq_tbl[1];
690
5.83M
            do {
691
5.83M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
5.83M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
5.83M
                const unsigned rc_tok = cf[rc];
695
5.83M
                unsigned tok;
696
5.83M
                int dq;
697
698
                // residual
699
5.83M
                if (rc_tok >= (15 << 11)) {
700
96.0k
                    tok = read_golomb(&ts->msac) + 15;
701
96.0k
                    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
96.0k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
96.0k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
96.0k
                    dq = umin(dq, cf_max + sign);
711
5.73M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
5.73M
                    tok = rc_tok >> 11;
714
5.73M
                    dq = ((ac_dq * tok) >> dq_shift);
715
5.73M
                    assert(dq <= cf_max);
716
5.73M
                }
717
5.83M
                cul_level += tok;
718
5.83M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
5.83M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
5.83M
            } while (rc);
722
1.25M
        }
723
828k
    }
724
725
    // context
726
1.83M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
1.83M
    return eob;
729
1.52M
}
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
560k
{
737
560k
    const Dav1dFrameContext *const f = t->f;
738
560k
    Dav1dTileState *const ts = t->ts;
739
560k
    const Dav1dDSPContext *const dsp = f->dsp;
740
560k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
560k
    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
560k
    if (depth < 2 && tx_split[depth] &&
746
42.9k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
33.0k
    {
748
33.0k
        const enum RectTxfmSize sub = t_dim->sub;
749
33.0k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
33.0k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
33.0k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
33.0k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
33.0k
        t->bx += txsw;
755
33.0k
        if (txw >= txh && t->bx < f->bw)
756
22.2k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
22.2k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
33.0k
        t->bx -= txsw;
759
33.0k
        t->by += txsh;
760
33.0k
        if (txh >= txw && t->by < f->bh) {
761
22.8k
            if (dst)
762
9.57k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
22.8k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
22.8k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
22.8k
            t->bx += txsw;
766
22.8k
            if (txw >= txh && t->bx < f->bw)
767
13.0k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
13.0k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
22.8k
            t->bx -= txsw;
770
22.8k
        }
771
33.0k
        t->by -= txsh;
772
527k
    } else {
773
527k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
527k
        enum TxfmType txtp;
775
527k
        uint8_t cf_ctx;
776
527k
        int eob;
777
527k
        coef *cf;
778
779
527k
        if (t->frame_thread.pass) {
780
527k
            const int p = t->frame_thread.pass & 1;
781
527k
            assert(ts->frame_thread[p].cf);
782
527k
            cf = ts->frame_thread[p].cf;
783
527k
            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
527k
        if (t->frame_thread.pass != 2) {
788
301k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
301k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
301k
            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
301k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
301k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
301k
#define set_ctx(rep_macro) \
796
1.27M
            for (int y = 0; y < txh; y++) { \
797
976k
                rep_macro(txtp_map, 0, txtp); \
798
976k
                txtp_map += 32; \
799
976k
            }
800
301k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
301k
            case_set_upto16(t_dim->lw);
802
301k
#undef set_ctx
803
301k
            if (t->frame_thread.pass == 1)
804
301k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
301k
        } else {
806
225k
            const int cbi = *ts->frame_thread[0].cbi++;
807
225k
            eob  = cbi >> 5;
808
225k
            txtp = cbi & 0x1f;
809
225k
        }
810
527k
        if (!(t->frame_thread.pass & 1)) {
811
226k
            assert(dst);
812
226k
            if (eob >= 0) {
813
137k
                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
137k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
137k
                                              HIGHBD_CALL_SUFFIX);
817
137k
                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
137k
            }
820
226k
        }
821
527k
    }
822
560k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
2.18M
{
827
2.18M
    const Dav1dFrameContext *const f = t->f;
828
2.18M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.18M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.18M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.18M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.18M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.18M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.18M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.18M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.97M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.81M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.18M
    if (b->skip) {
840
1.39M
        BlockContext *const a = t->a;
841
1.39M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.39M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.39M
        if (has_chroma) {
844
1.02M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.02M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.02M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.02M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.02M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.02M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.02M
        }
851
1.39M
        return;
852
1.39M
    }
853
854
791k
    Dav1dTileState *const ts = t->ts;
855
791k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
791k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
791k
    assert(t->frame_thread.pass == 1);
858
791k
    assert(!b->skip);
859
791k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
791k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
791k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.62M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
830k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.71M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
881k
            const int sub_w4 = imin(w4, init_x + 16);
867
881k
            int y_off = !!init_y, y, x;
868
1.91M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.03M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.03M
            {
871
1.03M
                int x_off = !!init_x;
872
2.68M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.65M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.65M
                {
875
1.65M
                    if (!b->intra) {
876
266k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
266k
                                       x_off, y_off, NULL);
878
1.38M
                    } else {
879
1.38M
                        uint8_t cf_ctx = 0x40;
880
1.38M
                        enum TxfmType txtp;
881
1.38M
                        const int eob =
882
1.38M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.38M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.38M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.38M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
1.38M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.38M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.38M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.38M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.38M
                    }
893
1.65M
                }
894
1.03M
                t->bx -= x;
895
1.03M
            }
896
881k
            t->by -= y;
897
898
881k
            if (!has_chroma) continue;
899
900
716k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
716k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.14M
            for (int pl = 0; pl < 2; pl++) {
903
2.99M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.56M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.56M
                {
906
3.51M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.95M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.95M
                    {
909
1.95M
                        uint8_t cf_ctx = 0x40;
910
1.95M
                        enum TxfmType txtp;
911
1.95M
                        if (!b->intra)
912
461k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
461k
                                                        bx4 + (x << ss_hor)];
914
1.95M
                        const int eob =
915
1.95M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.95M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.95M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.95M
                                         &txtp, &cf_ctx);
919
1.95M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.95M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.95M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.95M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.95M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.95M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.95M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.95M
                    }
930
1.56M
                    t->bx -= x << ss_hor;
931
1.56M
                }
932
1.43M
                t->by -= y << ss_ver;
933
1.43M
            }
934
716k
        }
935
830k
    }
936
791k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
1.09M
{
827
1.09M
    const Dav1dFrameContext *const f = t->f;
828
1.09M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.09M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.09M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.09M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.09M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.09M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.09M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.09M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.00M
                           (bw4 > ss_hor || t->bx & 1) &&
837
921k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.09M
    if (b->skip) {
840
738k
        BlockContext *const a = t->a;
841
738k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
738k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
738k
        if (has_chroma) {
844
549k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
549k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
549k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
549k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
549k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
549k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
549k
        }
851
738k
        return;
852
738k
    }
853
854
356k
    Dav1dTileState *const ts = t->ts;
855
356k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
356k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
356k
    assert(t->frame_thread.pass == 1);
858
356k
    assert(!b->skip);
859
356k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
356k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
356k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
732k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
375k
        const int sub_h4 = imin(h4, 16 + init_y);
865
773k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
397k
            const int sub_w4 = imin(w4, init_x + 16);
867
397k
            int y_off = !!init_y, y, x;
868
856k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
458k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
458k
            {
871
458k
                int x_off = !!init_x;
872
1.17M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
719k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
719k
                {
875
719k
                    if (!b->intra) {
876
156k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
156k
                                       x_off, y_off, NULL);
878
562k
                    } else {
879
562k
                        uint8_t cf_ctx = 0x40;
880
562k
                        enum TxfmType txtp;
881
562k
                        const int eob =
882
562k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
562k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
562k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
562k
                        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
562k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
562k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
562k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
562k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
562k
                    }
893
719k
                }
894
458k
                t->bx -= x;
895
458k
            }
896
397k
            t->by -= y;
897
898
397k
            if (!has_chroma) continue;
899
900
326k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
326k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
975k
            for (int pl = 0; pl < 2; pl++) {
903
1.35M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
705k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
705k
                {
906
1.56M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
857k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
857k
                    {
909
857k
                        uint8_t cf_ctx = 0x40;
910
857k
                        enum TxfmType txtp;
911
857k
                        if (!b->intra)
912
275k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
275k
                                                        bx4 + (x << ss_hor)];
914
857k
                        const int eob =
915
857k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
857k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
857k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
857k
                                         &txtp, &cf_ctx);
919
857k
                        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
857k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
857k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
857k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
857k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
857k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
857k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
857k
                    }
930
705k
                    t->bx -= x << ss_hor;
931
705k
                }
932
649k
                t->by -= y << ss_ver;
933
649k
            }
934
326k
        }
935
375k
    }
936
356k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.09M
{
827
1.09M
    const Dav1dFrameContext *const f = t->f;
828
1.09M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.09M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.09M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.09M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.09M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.09M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.09M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.09M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
967k
                           (bw4 > ss_hor || t->bx & 1) &&
837
893k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.09M
    if (b->skip) {
840
656k
        BlockContext *const a = t->a;
841
656k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
656k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
656k
        if (has_chroma) {
844
474k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
474k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
474k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
474k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
474k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
474k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
474k
        }
851
656k
        return;
852
656k
    }
853
854
434k
    Dav1dTileState *const ts = t->ts;
855
434k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
434k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
434k
    assert(t->frame_thread.pass == 1);
858
434k
    assert(!b->skip);
859
434k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
434k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
434k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
889k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
455k
        const int sub_h4 = imin(h4, 16 + init_y);
865
939k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
484k
            const int sub_w4 = imin(w4, init_x + 16);
867
484k
            int y_off = !!init_y, y, x;
868
1.06M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
576k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
576k
            {
871
576k
                int x_off = !!init_x;
872
1.50M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
931k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
931k
                {
875
931k
                    if (!b->intra) {
876
110k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
110k
                                       x_off, y_off, NULL);
878
821k
                    } else {
879
821k
                        uint8_t cf_ctx = 0x40;
880
821k
                        enum TxfmType txtp;
881
821k
                        const int eob =
882
821k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
821k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
821k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
821k
                        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
821k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
821k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
821k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
821k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
821k
                    }
893
931k
                }
894
576k
                t->bx -= x;
895
576k
            }
896
484k
            t->by -= y;
897
898
484k
            if (!has_chroma) continue;
899
900
390k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
390k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.17M
            for (int pl = 0; pl < 2; pl++) {
903
1.63M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
855k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
855k
                {
906
1.95M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.09M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.09M
                    {
909
1.09M
                        uint8_t cf_ctx = 0x40;
910
1.09M
                        enum TxfmType txtp;
911
1.09M
                        if (!b->intra)
912
186k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
186k
                                                        bx4 + (x << ss_hor)];
914
1.09M
                        const int eob =
915
1.09M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.09M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.09M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.09M
                                         &txtp, &cf_ctx);
919
1.09M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.09M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.09M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.09M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.09M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.09M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.09M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.09M
                    }
930
855k
                    t->bx -= x << ss_hor;
931
855k
                }
932
780k
                t->by -= y << ss_ver;
933
780k
            }
934
390k
        }
935
455k
    }
936
434k
}
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
625k
{
945
625k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
625k
    const Dav1dFrameContext *const f = t->f;
947
625k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
625k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
625k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
625k
    const int mvx = mv.x, mvy = mv.y;
951
625k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
625k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
625k
    const pixel *ref;
954
955
625k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
510k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
510k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
510k
        int w, h;
959
960
510k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
363k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
363k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
363k
        } else {
964
146k
            w = f->bw * 4 >> ss_hor;
965
146k
            h = f->bh * 4 >> ss_ver;
966
146k
        }
967
510k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
419k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
319k
            dy + bh4 * v_mul + !!my * 4 > h)
970
246k
        {
971
246k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
246k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
246k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
246k
                                emu_edge_buf, 192 * sizeof(pixel),
975
246k
                                refp->p.data[pl], ref_stride);
976
246k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
246k
            ref_stride = 192 * sizeof(pixel);
978
263k
        } else {
979
263k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
263k
        }
981
982
510k
        if (dst8 != NULL) {
983
437k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
437k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
437k
                                     HIGHBD_CALL_SUFFIX);
986
437k
        } else {
987
72.2k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
72.2k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
72.2k
                                      HIGHBD_CALL_SUFFIX);
990
72.2k
        }
991
510k
    } else {
992
115k
        assert(refp != &f->sr_cur);
993
994
115k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
115k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
231k
#define scale_mv(res, val, scale) do { \
997
231k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
231k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
231k
        } while (0)
1000
115k
        int pos_y, pos_x;
1001
115k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
115k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
115k
#undef scale_mv
1004
115k
        const int left = pos_x >> 10;
1005
115k
        const int top = pos_y >> 10;
1006
115k
        const int right =
1007
115k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
115k
        const int bottom =
1009
115k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
115k
        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
115k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
115k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
115k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
79.5k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
79.5k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
79.5k
                                w, h, left - 3, top - 3,
1023
79.5k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
79.5k
                                refp->p.data[pl], ref_stride);
1025
79.5k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
79.5k
            ref_stride = 320 * sizeof(pixel);
1027
79.5k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
79.5k
        } else {
1029
36.0k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
36.0k
        }
1031
1032
115k
        if (dst8 != NULL) {
1033
96.2k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
96.2k
                                            bw4 * h_mul, bh4 * v_mul,
1035
96.2k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
96.2k
                                            f->svc[refidx][0].step,
1037
96.2k
                                            f->svc[refidx][1].step
1038
96.2k
                                            HIGHBD_CALL_SUFFIX);
1039
96.2k
        } else {
1040
19.2k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
19.2k
                                             bw4 * h_mul, bh4 * v_mul,
1042
19.2k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
19.2k
                                             f->svc[refidx][0].step,
1044
19.2k
                                             f->svc[refidx][1].step
1045
19.2k
                                             HIGHBD_CALL_SUFFIX);
1046
19.2k
        }
1047
115k
    }
1048
1049
625k
    return 0;
1050
625k
}
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
50.6k
{
1057
50.6k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
50.6k
    const Dav1dFrameContext *const f = t->f;
1059
50.6k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
50.6k
    pixel *const lap = bitfn(t->scratch.lap);
1061
50.6k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
50.6k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
50.6k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
50.6k
    int res;
1065
1066
50.6k
    if (t->by > t->ts->tiling.row_start &&
1067
42.6k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
37.8k
    {
1069
78.9k
        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
41.0k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
41.0k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
41.0k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
41.0k
            if (a_r->ref.ref[0] > 0) {
1076
40.9k
                const int ow4 = imin(step4, b_dim[0]);
1077
40.9k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
40.9k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
40.9k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
40.9k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
40.9k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
40.9k
                if (res) return res;
1083
40.9k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
40.9k
                                   h_mul * ow4, v_mul * oh4);
1085
40.9k
                i++;
1086
40.9k
            }
1087
41.0k
            x += step4;
1088
41.0k
        }
1089
37.8k
    }
1090
1091
50.6k
    if (t->bx > t->ts->tiling.col_start)
1092
87.3k
        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
45.1k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
45.1k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
45.1k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
45.1k
            if (l_r->ref.ref[0] > 0) {
1099
44.7k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
44.7k
                const int oh4 = imin(step4, b_dim[1]);
1101
44.7k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
44.7k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
44.7k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
44.7k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
44.7k
                if (res) return res;
1106
44.7k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
44.7k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
44.7k
                i++;
1109
44.7k
            }
1110
45.1k
            y += step4;
1111
45.1k
        }
1112
50.6k
    return 0;
1113
50.6k
}
1114
1115
static int warp_affine(Dav1dTaskContext *const t,
1116
                       pixel *dst8, int16_t *dst16, const ptrdiff_t dstride,
1117
                       const uint8_t *const b_dim, const int pl,
1118
                       const Dav1dThreadPicture *const refp,
1119
                       const Dav1dWarpedMotionParams *const wmp)
1120
18.9k
{
1121
18.9k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
18.9k
    const Dav1dFrameContext *const f = t->f;
1123
18.9k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
18.9k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
18.9k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
18.9k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
18.9k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
18.9k
    const int32_t *const mat = wmp->matrix;
1129
18.9k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
18.9k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
59.7k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
40.7k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
40.7k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
40.7k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
243k
        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
202k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
202k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
202k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
202k
            const int dx = (int) (mvx >> 16) - 4;
1144
202k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
202k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
202k
            const int dy = (int) (mvy >> 16) - 4;
1147
202k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
202k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
202k
            const pixel *ref_ptr;
1151
202k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
202k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
145k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
145k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
145k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
145k
                                    refp->p.data[pl], ref_stride);
1158
145k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
145k
                ref_stride = 32 * sizeof(pixel);
1160
145k
            } else {
1161
56.6k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
56.6k
            }
1163
202k
            if (dst16 != NULL)
1164
25.6k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
25.6k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
176k
            else
1167
176k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
176k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
202k
        }
1170
40.7k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
9.90k
        else      dst16 += 8 * dstride;
1172
40.7k
    }
1173
18.9k
    return 0;
1174
18.9k
}
1175
1176
void bytefn(dav1d_recon_b_intra)(Dav1dTaskContext *const t, const enum BlockSize bs,
1177
                                 const enum EdgeFlags intra_edge_flags,
1178
                                 const Av1Block *const b)
1179
1.27M
{
1180
1.27M
    Dav1dTileState *const ts = t->ts;
1181
1.27M
    const Dav1dFrameContext *const f = t->f;
1182
1.27M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.27M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.27M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.27M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.27M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.27M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.27M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.27M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.27M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.27M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
1.18M
                           (bw4 > ss_hor || t->bx & 1) &&
1193
1.09M
                           (bh4 > ss_ver || t->by & 1);
1194
1.27M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.27M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.27M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.27M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.27M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.58M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.31M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.31M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.69M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.38M
            if (b->pal_sz[0]) {
1208
7.79k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
7.79k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
7.79k
                const uint8_t *pal_idx;
1211
7.79k
                if (t->frame_thread.pass) {
1212
7.79k
                    const int p = t->frame_thread.pass & 1;
1213
7.79k
                    assert(ts->frame_thread[p].pal_idx);
1214
7.79k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
7.79k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
7.79k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
7.79k
                const pixel *const pal = t->frame_thread.pass ?
1220
7.79k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
7.79k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
7.79k
                    bytefn(t->scratch.pal)[0];
1223
7.79k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
7.79k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
7.79k
                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
7.79k
            }
1229
1230
1.38M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.38M
                                     sm_flag(&t->l, by4) |
1232
1.38M
                                     intra_edge_filter_flag);
1233
1.38M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.31M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.38M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.31M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.38M
            int y, x;
1238
1.38M
            const int sub_w4 = imin(w4, init_x + 16);
1239
3.04M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.66M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.66M
            {
1242
1.66M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.66M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.66M
                                    t->bx + init_x);
1245
4.29M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.62M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.62M
                {
1248
2.62M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.61M
                    int angle = b->y_angle;
1251
2.61M
                    const enum EdgeFlags edge_flags =
1252
2.61M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.86M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.61M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.75M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.61M
                    const pixel *top_sb_edge = NULL;
1257
2.61M
                    if (!(t->by & (f->sb_step - 1))) {
1258
495k
                        top_sb_edge = f->ipred_edge[0];
1259
495k
                        const int sby = t->by >> f->sb_shift;
1260
495k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
495k
                    }
1262
2.61M
                    const enum IntraPredMode m =
1263
2.61M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.61M
                                                          t->bx > ts->tiling.col_start,
1265
2.61M
                                                          t->by,
1266
2.61M
                                                          t->by > ts->tiling.row_start,
1267
2.61M
                                                          ts->tiling.col_end,
1268
2.61M
                                                          ts->tiling.row_end,
1269
2.61M
                                                          edge_flags, dst,
1270
2.61M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.61M
                                                          b->y_mode, &angle,
1272
2.61M
                                                          t_dim->w, t_dim->h,
1273
2.61M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.61M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.61M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.61M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.61M
                                             angle | intra_flags,
1278
2.61M
                                             4 * f->bw - 4 * t->bx,
1279
2.61M
                                             4 * f->bh - 4 * t->by
1280
2.61M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.61M
                    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
2.62M
                skip_y_pred: {}
1293
2.62M
                    if (!b->skip) {
1294
774k
                        coef *cf;
1295
774k
                        int eob;
1296
774k
                        enum TxfmType txtp;
1297
774k
                        if (t->frame_thread.pass) {
1298
774k
                            const int p = t->frame_thread.pass & 1;
1299
774k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
774k
                            cf = ts->frame_thread[p].cf;
1301
774k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
774k
                            eob  = cbi >> 5;
1303
774k
                            txtp = cbi & 0x1f;
1304
18.4E
                        } else {
1305
18.4E
                            uint8_t cf_ctx;
1306
18.4E
                            cf = bitfn(t->cf);
1307
18.4E
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
18.4E
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
18.4E
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
18.4E
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
18.4E
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
18.4E
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
18.4E
                        }
1316
774k
                        if (eob >= 0) {
1317
547k
                            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
547k
                            dsp->itx.itxfm_add[b->tx]
1321
547k
                                              [txtp](dst,
1322
547k
                                                     f->cur.stride[0],
1323
547k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
547k
                            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
547k
                        }
1328
1.85M
                    } 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
2.62M
                    dst += 4 * t_dim->w;
1333
2.62M
                }
1334
1.66M
                t->bx -= x;
1335
1.66M
            }
1336
1.38M
            t->by -= y;
1337
1338
1.38M
            if (!has_chroma) continue;
1339
1340
1.10M
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
1.10M
            if (b->uv_mode == CFL_PRED) {
1343
202k
                assert(!init_x && !init_y);
1344
1345
202k
                int16_t *const ac = t->scratch.ac;
1346
202k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
202k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
202k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
202k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
202k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
202k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
202k
                const int furthest_r =
1354
202k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
202k
                const int furthest_b =
1356
202k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
202k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
202k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
202k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
202k
                                                         cbw4 * 4, cbh4 * 4);
1361
608k
                for (int pl = 0; pl < 2; pl++) {
1362
405k
                    if (!b->cfl_alpha[pl]) continue;
1363
324k
                    int angle = 0;
1364
324k
                    const pixel *top_sb_edge = NULL;
1365
324k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
69.1k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
69.1k
                        const int sby = t->by >> f->sb_shift;
1368
69.1k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
69.1k
                    }
1370
324k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
324k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
324k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
324k
                    const enum IntraPredMode m =
1374
324k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
324k
                                                          ypos, ypos > ystart,
1376
324k
                                                          ts->tiling.col_end >> ss_hor,
1377
324k
                                                          ts->tiling.row_end >> ss_ver,
1378
324k
                                                          0, uv_dst[pl], stride,
1379
324k
                                                          top_sb_edge, DC_PRED, &angle,
1380
324k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
324k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
324k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
324k
                                           uv_t_dim->w * 4,
1384
324k
                                           uv_t_dim->h * 4,
1385
324k
                                           ac, b->cfl_alpha[pl]
1386
324k
                                           HIGHBD_CALL_SUFFIX);
1387
324k
                }
1388
202k
                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
905k
            } else if (b->pal_sz[1]) {
1394
3.54k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.54k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.54k
                const pixel (*pal)[8];
1397
3.54k
                const uint8_t *pal_idx;
1398
3.54k
                if (t->frame_thread.pass) {
1399
3.54k
                    const int p = t->frame_thread.pass & 1;
1400
3.54k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.54k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.54k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.54k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.54k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.54k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.54k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.54k
                                       f->cur.stride[1], pal[1],
1412
3.54k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.54k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.54k
                                       f->cur.stride[1], pal[2],
1415
3.54k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.54k
                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
3.54k
            }
1425
1426
1.10M
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
1.10M
                                 sm_uv_flag(&t->l, cby4);
1428
1.10M
            const int uv_sb_has_tr =
1429
1.10M
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
1.04M
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
1.10M
            const int uv_sb_has_bl =
1432
1.10M
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
1.04M
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
1.10M
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
3.32M
            for (int pl = 0; pl < 2; pl++) {
1436
4.55M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
2.34M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
2.34M
                {
1439
2.34M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
2.34M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
2.34M
                                        ((t->bx + init_x) >> ss_hor));
1442
5.01M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.66M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.67M
                    {
1445
2.67M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
2.34M
                            b->pal_sz[1])
1447
331k
                        {
1448
331k
                            goto skip_uv_pred;
1449
331k
                        }
1450
1451
2.33M
                        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
2.33M
                        const enum EdgeFlags edge_flags =
1456
2.33M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
996k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.61M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
2.33M
                            ((x > (init_x >> ss_hor) ||
1460
2.01M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.46M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
2.33M
                        const pixel *top_sb_edge = NULL;
1463
2.33M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
651k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
651k
                            const int sby = t->by >> f->sb_shift;
1466
651k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
651k
                        }
1468
2.33M
                        const enum IntraPredMode uv_mode =
1469
2.33M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
2.33M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
2.33M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
2.33M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
2.33M
                        const enum IntraPredMode m =
1474
2.33M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
2.33M
                                                              ypos, ypos > ystart,
1476
2.33M
                                                              ts->tiling.col_end >> ss_hor,
1477
2.33M
                                                              ts->tiling.row_end >> ss_ver,
1478
2.33M
                                                              edge_flags, dst, stride,
1479
2.33M
                                                              top_sb_edge, uv_mode,
1480
2.33M
                                                              &angle, uv_t_dim->w,
1481
2.33M
                                                              uv_t_dim->h,
1482
2.33M
                                                              f->seq_hdr->intra_edge_filter,
1483
2.33M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
2.33M
                        angle |= intra_edge_filter_flag;
1485
2.33M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
2.33M
                                                 uv_t_dim->w * 4,
1487
2.33M
                                                 uv_t_dim->h * 4,
1488
2.33M
                                                 angle | sm_uv_fl,
1489
2.33M
                                                 (4 * f->bw + ss_hor -
1490
2.33M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
2.33M
                                                 (4 * f->bh + ss_ver -
1492
2.33M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
2.33M
                                                 HIGHBD_CALL_SUFFIX);
1494
2.33M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.66M
                    skip_uv_pred: {}
1505
2.66M
                        if (!b->skip) {
1506
882k
                            enum TxfmType txtp;
1507
882k
                            int eob;
1508
882k
                            coef *cf;
1509
882k
                            if (t->frame_thread.pass) {
1510
882k
                                const int p = t->frame_thread.pass & 1;
1511
882k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
882k
                                cf = ts->frame_thread[p].cf;
1513
882k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
882k
                                eob  = cbi >> 5;
1515
882k
                                txtp = cbi & 0x1f;
1516
882k
                            } 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
882k
                            if (eob >= 0) {
1533
289k
                                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
289k
                                dsp->itx.itxfm_add[b->uvtx]
1537
289k
                                                  [txtp](dst, stride,
1538
289k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
289k
                                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
289k
                            }
1543
1.78M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
2.66M
                        dst += uv_t_dim->w * 4;
1548
2.66M
                    }
1549
2.34M
                    t->bx -= x << ss_hor;
1550
2.34M
                }
1551
2.21M
                t->by -= y << ss_ver;
1552
2.21M
            }
1553
1.10M
        }
1554
1.31M
    }
1555
1.27M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
560k
{
1180
560k
    Dav1dTileState *const ts = t->ts;
1181
560k
    const Dav1dFrameContext *const f = t->f;
1182
560k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
560k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
560k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
560k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
560k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
560k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
560k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
560k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
560k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
560k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
537k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
496k
                           (bh4 > ss_ver || t->by & 1);
1194
560k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
560k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
560k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
560k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
560k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.13M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
579k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
579k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.19M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
611k
            if (b->pal_sz[0]) {
1208
4.27k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
4.27k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
4.27k
                const uint8_t *pal_idx;
1211
4.27k
                if (t->frame_thread.pass) {
1212
4.27k
                    const int p = t->frame_thread.pass & 1;
1213
4.27k
                    assert(ts->frame_thread[p].pal_idx);
1214
4.27k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
4.27k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
4.27k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
4.27k
                const pixel *const pal = t->frame_thread.pass ?
1220
4.27k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
4.27k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
4.27k
                    bytefn(t->scratch.pal)[0];
1223
4.27k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
4.27k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
4.27k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
4.27k
            }
1229
1230
611k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
611k
                                     sm_flag(&t->l, by4) |
1232
611k
                                     intra_edge_filter_flag);
1233
611k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
579k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
611k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
579k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
611k
            int y, x;
1238
611k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.31M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
707k
                 y += t_dim->h, t->by += t_dim->h)
1241
706k
            {
1242
706k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
706k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
706k
                                    t->bx + init_x);
1245
1.74M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.03M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.03M
                {
1248
1.03M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.03M
                    int angle = b->y_angle;
1251
1.03M
                    const enum EdgeFlags edge_flags =
1252
1.03M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
741k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.03M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
682k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.03M
                    const pixel *top_sb_edge = NULL;
1257
1.03M
                    if (!(t->by & (f->sb_step - 1))) {
1258
227k
                        top_sb_edge = f->ipred_edge[0];
1259
227k
                        const int sby = t->by >> f->sb_shift;
1260
227k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
227k
                    }
1262
1.03M
                    const enum IntraPredMode m =
1263
1.03M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.03M
                                                          t->bx > ts->tiling.col_start,
1265
1.03M
                                                          t->by,
1266
1.03M
                                                          t->by > ts->tiling.row_start,
1267
1.03M
                                                          ts->tiling.col_end,
1268
1.03M
                                                          ts->tiling.row_end,
1269
1.03M
                                                          edge_flags, dst,
1270
1.03M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.03M
                                                          b->y_mode, &angle,
1272
1.03M
                                                          t_dim->w, t_dim->h,
1273
1.03M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.03M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.03M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.03M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.03M
                                             angle | intra_flags,
1278
1.03M
                                             4 * f->bw - 4 * t->bx,
1279
1.03M
                                             4 * f->bh - 4 * t->by
1280
1.03M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.03M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.03M
                skip_y_pred: {}
1293
1.03M
                    if (!b->skip) {
1294
271k
                        coef *cf;
1295
271k
                        int eob;
1296
271k
                        enum TxfmType txtp;
1297
271k
                        if (t->frame_thread.pass) {
1298
271k
                            const int p = t->frame_thread.pass & 1;
1299
271k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
271k
                            cf = ts->frame_thread[p].cf;
1301
271k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
271k
                            eob  = cbi >> 5;
1303
271k
                            txtp = cbi & 0x1f;
1304
271k
                        } 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
271k
                        if (eob >= 0) {
1317
192k
                            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
192k
                            dsp->itx.itxfm_add[b->tx]
1321
192k
                                              [txtp](dst,
1322
192k
                                                     f->cur.stride[0],
1323
192k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
192k
                            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
192k
                        }
1328
765k
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.03M
                    dst += 4 * t_dim->w;
1333
1.03M
                }
1334
707k
                t->bx -= x;
1335
707k
            }
1336
611k
            t->by -= y;
1337
1338
611k
            if (!has_chroma) continue;
1339
1340
504k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
504k
            if (b->uv_mode == CFL_PRED) {
1343
93.9k
                assert(!init_x && !init_y);
1344
1345
93.9k
                int16_t *const ac = t->scratch.ac;
1346
93.9k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
93.9k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
93.9k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
93.9k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
93.9k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
93.9k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
93.9k
                const int furthest_r =
1354
93.9k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
93.9k
                const int furthest_b =
1356
93.9k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
93.9k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
93.9k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
93.9k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
93.9k
                                                         cbw4 * 4, cbh4 * 4);
1361
281k
                for (int pl = 0; pl < 2; pl++) {
1362
187k
                    if (!b->cfl_alpha[pl]) continue;
1363
152k
                    int angle = 0;
1364
152k
                    const pixel *top_sb_edge = NULL;
1365
152k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
34.3k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
34.3k
                        const int sby = t->by >> f->sb_shift;
1368
34.3k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
34.3k
                    }
1370
152k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
152k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
152k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
152k
                    const enum IntraPredMode m =
1374
152k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
152k
                                                          ypos, ypos > ystart,
1376
152k
                                                          ts->tiling.col_end >> ss_hor,
1377
152k
                                                          ts->tiling.row_end >> ss_ver,
1378
152k
                                                          0, uv_dst[pl], stride,
1379
152k
                                                          top_sb_edge, DC_PRED, &angle,
1380
152k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
152k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
152k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
152k
                                           uv_t_dim->w * 4,
1384
152k
                                           uv_t_dim->h * 4,
1385
152k
                                           ac, b->cfl_alpha[pl]
1386
152k
                                           HIGHBD_CALL_SUFFIX);
1387
152k
                }
1388
93.9k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
410k
            } else if (b->pal_sz[1]) {
1394
2.38k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
2.38k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
2.38k
                const pixel (*pal)[8];
1397
2.38k
                const uint8_t *pal_idx;
1398
2.38k
                if (t->frame_thread.pass) {
1399
2.38k
                    const int p = t->frame_thread.pass & 1;
1400
2.38k
                    assert(ts->frame_thread[p].pal_idx);
1401
2.38k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
2.38k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
2.38k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
2.38k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
2.38k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
2.38k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
2.38k
                                       f->cur.stride[1], pal[1],
1412
2.38k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
2.38k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
2.38k
                                       f->cur.stride[1], pal[2],
1415
2.38k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
2.38k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
2.38k
            }
1425
1426
504k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
504k
                                 sm_uv_flag(&t->l, cby4);
1428
504k
            const int uv_sb_has_tr =
1429
504k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
472k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
504k
            const int uv_sb_has_bl =
1432
504k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
472k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
504k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.51M
            for (int pl = 0; pl < 2; pl++) {
1436
2.06M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.05M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.05M
                {
1439
1.05M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.05M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.05M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.21M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.16M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.16M
                    {
1445
1.16M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.01M
                            b->pal_sz[1])
1447
156k
                        {
1448
156k
                            goto skip_uv_pred;
1449
156k
                        }
1450
1451
1.00M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
1.00M
                        const enum EdgeFlags edge_flags =
1456
1.00M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
388k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
714k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.00M
                            ((x > (init_x >> ss_hor) ||
1460
895k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
623k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.00M
                        const pixel *top_sb_edge = NULL;
1463
1.00M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
317k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
317k
                            const int sby = t->by >> f->sb_shift;
1466
317k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
317k
                        }
1468
1.00M
                        const enum IntraPredMode uv_mode =
1469
1.00M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.00M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.00M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.00M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.00M
                        const enum IntraPredMode m =
1474
1.00M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.00M
                                                              ypos, ypos > ystart,
1476
1.00M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.00M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.00M
                                                              edge_flags, dst, stride,
1479
1.00M
                                                              top_sb_edge, uv_mode,
1480
1.00M
                                                              &angle, uv_t_dim->w,
1481
1.00M
                                                              uv_t_dim->h,
1482
1.00M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.00M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.00M
                        angle |= intra_edge_filter_flag;
1485
1.00M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.00M
                                                 uv_t_dim->w * 4,
1487
1.00M
                                                 uv_t_dim->h * 4,
1488
1.00M
                                                 angle | sm_uv_fl,
1489
1.00M
                                                 (4 * f->bw + ss_hor -
1490
1.00M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.00M
                                                 (4 * f->bh + ss_ver -
1492
1.00M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.00M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.00M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
1.16M
                    skip_uv_pred: {}
1505
1.16M
                        if (!b->skip) {
1506
320k
                            enum TxfmType txtp;
1507
320k
                            int eob;
1508
320k
                            coef *cf;
1509
320k
                            if (t->frame_thread.pass) {
1510
320k
                                const int p = t->frame_thread.pass & 1;
1511
320k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
320k
                                cf = ts->frame_thread[p].cf;
1513
320k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
320k
                                eob  = cbi >> 5;
1515
320k
                                txtp = cbi & 0x1f;
1516
320k
                            } 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
320k
                            if (eob >= 0) {
1533
126k
                                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
126k
                                dsp->itx.itxfm_add[b->uvtx]
1537
126k
                                                  [txtp](dst, stride,
1538
126k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
126k
                                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
126k
                            }
1543
844k
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
1.16M
                        dst += uv_t_dim->w * 4;
1548
1.16M
                    }
1549
1.05M
                    t->bx -= x << ss_hor;
1550
1.05M
                }
1551
1.00M
                t->by -= y << ss_ver;
1552
1.00M
            }
1553
504k
        }
1554
579k
    }
1555
560k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
714k
{
1180
714k
    Dav1dTileState *const ts = t->ts;
1181
714k
    const Dav1dFrameContext *const f = t->f;
1182
714k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
714k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
714k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
714k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
714k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
714k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
714k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
714k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
714k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
714k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
648k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
601k
                           (bh4 > ss_ver || t->by & 1);
1194
714k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
714k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
714k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
714k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
714k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.44M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
734k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
734k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.50M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
770k
            if (b->pal_sz[0]) {
1208
3.52k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
3.52k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
3.52k
                const uint8_t *pal_idx;
1211
3.52k
                if (t->frame_thread.pass) {
1212
3.52k
                    const int p = t->frame_thread.pass & 1;
1213
3.52k
                    assert(ts->frame_thread[p].pal_idx);
1214
3.52k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
3.52k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
3.52k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
3.52k
                const pixel *const pal = t->frame_thread.pass ?
1220
3.52k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
3.52k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
3.52k
                    bytefn(t->scratch.pal)[0];
1223
3.52k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
3.52k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
3.52k
                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
3.52k
            }
1229
1230
770k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
770k
                                     sm_flag(&t->l, by4) |
1232
770k
                                     intra_edge_filter_flag);
1233
770k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
734k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
770k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
734k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
770k
            int y, x;
1238
770k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.73M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
960k
                 y += t_dim->h, t->by += t_dim->h)
1241
961k
            {
1242
961k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
961k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
961k
                                    t->bx + init_x);
1245
2.55M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.59M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.59M
                {
1248
1.59M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.58M
                    int angle = b->y_angle;
1251
1.58M
                    const enum EdgeFlags edge_flags =
1252
1.58M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.12M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.58M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.07M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.58M
                    const pixel *top_sb_edge = NULL;
1257
1.58M
                    if (!(t->by & (f->sb_step - 1))) {
1258
268k
                        top_sb_edge = f->ipred_edge[0];
1259
268k
                        const int sby = t->by >> f->sb_shift;
1260
268k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
268k
                    }
1262
1.58M
                    const enum IntraPredMode m =
1263
1.58M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.58M
                                                          t->bx > ts->tiling.col_start,
1265
1.58M
                                                          t->by,
1266
1.58M
                                                          t->by > ts->tiling.row_start,
1267
1.58M
                                                          ts->tiling.col_end,
1268
1.58M
                                                          ts->tiling.row_end,
1269
1.58M
                                                          edge_flags, dst,
1270
1.58M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.58M
                                                          b->y_mode, &angle,
1272
1.58M
                                                          t_dim->w, t_dim->h,
1273
1.58M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.58M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.58M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.58M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.58M
                                             angle | intra_flags,
1278
1.58M
                                             4 * f->bw - 4 * t->bx,
1279
1.58M
                                             4 * f->bh - 4 * t->by
1280
1.58M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.58M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.59M
                skip_y_pred: {}
1293
1.59M
                    if (!b->skip) {
1294
503k
                        coef *cf;
1295
503k
                        int eob;
1296
503k
                        enum TxfmType txtp;
1297
503k
                        if (t->frame_thread.pass) {
1298
503k
                            const int p = t->frame_thread.pass & 1;
1299
503k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
503k
                            cf = ts->frame_thread[p].cf;
1301
503k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
503k
                            eob  = cbi >> 5;
1303
503k
                            txtp = cbi & 0x1f;
1304
18.4E
                        } else {
1305
18.4E
                            uint8_t cf_ctx;
1306
18.4E
                            cf = bitfn(t->cf);
1307
18.4E
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
18.4E
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
18.4E
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
18.4E
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
18.4E
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
18.4E
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
18.4E
                        }
1316
503k
                        if (eob >= 0) {
1317
354k
                            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
354k
                            dsp->itx.itxfm_add[b->tx]
1321
354k
                                              [txtp](dst,
1322
354k
                                                     f->cur.stride[0],
1323
354k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
354k
                            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
354k
                        }
1328
1.08M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.59M
                    dst += 4 * t_dim->w;
1333
1.59M
                }
1334
960k
                t->bx -= x;
1335
960k
            }
1336
769k
            t->by -= y;
1337
1338
769k
            if (!has_chroma) continue;
1339
1340
603k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
603k
            if (b->uv_mode == CFL_PRED) {
1343
108k
                assert(!init_x && !init_y);
1344
1345
108k
                int16_t *const ac = t->scratch.ac;
1346
108k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
108k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
108k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
108k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
108k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
108k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
108k
                const int furthest_r =
1354
108k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
108k
                const int furthest_b =
1356
108k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
108k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
108k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
108k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
108k
                                                         cbw4 * 4, cbh4 * 4);
1361
326k
                for (int pl = 0; pl < 2; pl++) {
1362
217k
                    if (!b->cfl_alpha[pl]) continue;
1363
172k
                    int angle = 0;
1364
172k
                    const pixel *top_sb_edge = NULL;
1365
172k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
34.7k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
34.7k
                        const int sby = t->by >> f->sb_shift;
1368
34.7k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
34.7k
                    }
1370
172k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
172k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
172k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
172k
                    const enum IntraPredMode m =
1374
172k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
172k
                                                          ypos, ypos > ystart,
1376
172k
                                                          ts->tiling.col_end >> ss_hor,
1377
172k
                                                          ts->tiling.row_end >> ss_ver,
1378
172k
                                                          0, uv_dst[pl], stride,
1379
172k
                                                          top_sb_edge, DC_PRED, &angle,
1380
172k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
172k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
172k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
172k
                                           uv_t_dim->w * 4,
1384
172k
                                           uv_t_dim->h * 4,
1385
172k
                                           ac, b->cfl_alpha[pl]
1386
172k
                                           HIGHBD_CALL_SUFFIX);
1387
172k
                }
1388
108k
                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
495k
            } else if (b->pal_sz[1]) {
1394
1.15k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.15k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.15k
                const pixel (*pal)[8];
1397
1.15k
                const uint8_t *pal_idx;
1398
1.15k
                if (t->frame_thread.pass) {
1399
1.15k
                    const int p = t->frame_thread.pass & 1;
1400
1.15k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.15k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.15k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.15k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.15k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.15k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.15k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.15k
                                       f->cur.stride[1], pal[1],
1412
1.15k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.15k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.15k
                                       f->cur.stride[1], pal[2],
1415
1.15k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.15k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.15k
            }
1425
1426
603k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
603k
                                 sm_uv_flag(&t->l, cby4);
1428
603k
            const int uv_sb_has_tr =
1429
603k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
570k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
603k
            const int uv_sb_has_bl =
1432
603k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
570k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
603k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.81M
            for (int pl = 0; pl < 2; pl++) {
1436
2.49M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.28M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.28M
                {
1439
1.28M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.28M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.28M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.79M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.50M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.50M
                    {
1445
1.50M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.33M
                            b->pal_sz[1])
1447
174k
                        {
1448
174k
                            goto skip_uv_pred;
1449
174k
                        }
1450
1451
1.33M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
1.33M
                        const enum EdgeFlags edge_flags =
1456
1.33M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
608k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
903k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.33M
                            ((x > (init_x >> ss_hor) ||
1460
1.11M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
840k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.33M
                        const pixel *top_sb_edge = NULL;
1463
1.33M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
333k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
333k
                            const int sby = t->by >> f->sb_shift;
1466
333k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
333k
                        }
1468
1.33M
                        const enum IntraPredMode uv_mode =
1469
1.33M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.33M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.33M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.33M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.33M
                        const enum IntraPredMode m =
1474
1.33M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.33M
                                                              ypos, ypos > ystart,
1476
1.33M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.33M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.33M
                                                              edge_flags, dst, stride,
1479
1.33M
                                                              top_sb_edge, uv_mode,
1480
1.33M
                                                              &angle, uv_t_dim->w,
1481
1.33M
                                                              uv_t_dim->h,
1482
1.33M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.33M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.33M
                        angle |= intra_edge_filter_flag;
1485
1.33M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.33M
                                                 uv_t_dim->w * 4,
1487
1.33M
                                                 uv_t_dim->h * 4,
1488
1.33M
                                                 angle | sm_uv_fl,
1489
1.33M
                                                 (4 * f->bw + ss_hor -
1490
1.33M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.33M
                                                 (4 * f->bh + ss_ver -
1492
1.33M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.33M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.33M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
1.50M
                    skip_uv_pred: {}
1505
1.50M
                        if (!b->skip) {
1506
562k
                            enum TxfmType txtp;
1507
562k
                            int eob;
1508
562k
                            coef *cf;
1509
562k
                            if (t->frame_thread.pass) {
1510
562k
                                const int p = t->frame_thread.pass & 1;
1511
562k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
562k
                                cf = ts->frame_thread[p].cf;
1513
562k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
562k
                                eob  = cbi >> 5;
1515
562k
                                txtp = cbi & 0x1f;
1516
562k
                            } 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
562k
                            if (eob >= 0) {
1533
163k
                                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
163k
                                dsp->itx.itxfm_add[b->uvtx]
1537
163k
                                                  [txtp](dst, stride,
1538
163k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
163k
                                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
163k
                            }
1543
941k
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
1.50M
                        dst += uv_t_dim->w * 4;
1548
1.50M
                    }
1549
1.28M
                    t->bx -= x << ss_hor;
1550
1.28M
                }
1551
1.20M
                t->by -= y << ss_ver;
1552
1.20M
            }
1553
603k
        }
1554
734k
    }
1555
714k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
213k
{
1560
213k
    Dav1dTileState *const ts = t->ts;
1561
213k
    const Dav1dFrameContext *const f = t->f;
1562
213k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
213k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
213k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
213k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
213k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
213k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
213k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
213k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
213k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
155k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
148k
                           (bh4 > ss_ver || t->by & 1);
1573
213k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
213k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
213k
    int res;
1576
1577
    // prediction
1578
213k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
213k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
213k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
213k
    const ptrdiff_t uvdstoff =
1582
213k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
213k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
81.8k
        assert(!f->frame_hdr->super_res.enabled);
1586
81.8k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
81.8k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
81.8k
        if (res) return res;
1589
97.6k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
65.1k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
65.1k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
65.1k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
65.1k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
65.1k
            if (res) return res;
1595
65.1k
        }
1596
131k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
112k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
112k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
112k
        if (imin(bw4, bh4) > 1 &&
1601
72.2k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
70.2k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
4.03k
        {
1604
4.03k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
4.03k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
4.03k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
4.03k
            if (res) return res;
1608
108k
        } else {
1609
108k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
108k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
108k
            if (res) return res;
1612
108k
            if (b->motion_mode == MM_OBMC) {
1613
18.0k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
18.0k
                if (res) return res;
1615
18.0k
            }
1616
108k
        }
1617
112k
        if (b->interintra_type) {
1618
2.16k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.16k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.79k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.16k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.16k
            int angle = 0;
1623
2.16k
            const pixel *top_sb_edge = NULL;
1624
2.16k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.61k
                top_sb_edge = f->ipred_edge[0];
1626
1.61k
                const int sby = t->by >> f->sb_shift;
1627
1.61k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.61k
            }
1629
2.16k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.16k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.16k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.16k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.16k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.16k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.16k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.16k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.16k
                                     HIGHBD_CALL_SUFFIX);
1638
2.16k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.16k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.16k
        }
1641
1642
112k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
93.9k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
93.9k
        refmvs_block *const *r;
1647
93.9k
        if (is_sub8x8) {
1648
5.22k
            assert(ss_hor == 1);
1649
5.22k
            r = &t->rt.r[(t->by & 31) + 5];
1650
5.22k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
5.22k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
5.22k
            if (bw4 == 1 && bh4 == ss_ver)
1653
664
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
5.22k
        }
1655
1656
        // chroma prediction
1657
93.9k
        if (is_sub8x8) {
1658
5.09k
            assert(ss_hor == 1);
1659
5.09k
            ptrdiff_t h_off = 0, v_off = 0;
1660
5.09k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.90k
                for (int pl = 0; pl < 2; pl++) {
1662
1.27k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.27k
                             NULL, f->cur.stride[1],
1664
1.27k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.27k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.27k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.27k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.27k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.27k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.27k
                    if (res) return res;
1671
1.27k
                }
1672
635
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
635
                h_off = 2;
1674
635
            }
1675
5.09k
            if (bw4 == 1) {
1676
2.67k
                const enum Filter2d left_filter_2d =
1677
2.67k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
8.02k
                for (int pl = 0; pl < 2; pl++) {
1679
5.35k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
5.35k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
5.35k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
5.35k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
5.35k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
5.35k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
5.35k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
5.35k
                    if (res) return res;
1687
5.35k
                }
1688
2.67k
                h_off = 2;
1689
2.67k
            }
1690
5.09k
            if (bh4 == ss_ver) {
1691
3.05k
                const enum Filter2d top_filter_2d =
1692
3.05k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
9.17k
                for (int pl = 0; pl < 2; pl++) {
1694
6.11k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
6.11k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
6.11k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
6.11k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
6.11k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
6.11k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
6.11k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
6.11k
                    if (res) return res;
1702
6.11k
                }
1703
3.05k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
3.05k
            }
1705
15.2k
            for (int pl = 0; pl < 2; pl++) {
1706
10.1k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
10.1k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
10.1k
                         refp, b->ref[0], filter_2d);
1709
10.1k
                if (res) return res;
1710
10.1k
            }
1711
88.8k
        } else {
1712
88.8k
            if (imin(cbw4, cbh4) > 1 &&
1713
50.5k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
48.7k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
3.77k
            {
1716
11.3k
                for (int pl = 0; pl < 2; pl++) {
1717
7.55k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
7.55k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
7.55k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
7.55k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
7.55k
                    if (res) return res;
1722
7.55k
                }
1723
85.1k
            } else {
1724
255k
                for (int pl = 0; pl < 2; pl++) {
1725
170k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
170k
                             NULL, f->cur.stride[1],
1727
170k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
170k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
170k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
170k
                    if (res) return res;
1731
170k
                    if (b->motion_mode == MM_OBMC) {
1732
32.6k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
32.6k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
32.6k
                        if (res) return res;
1735
32.6k
                    }
1736
170k
                }
1737
85.1k
            }
1738
88.8k
            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.79k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
5.37k
                for (int pl = 0; pl < 2; pl++) {
1745
3.58k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
3.58k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
3.58k
                    enum IntraPredMode m =
1748
3.58k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
2.98k
                        SMOOTH_PRED : b->interintra_mode;
1750
3.58k
                    int angle = 0;
1751
3.58k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
3.58k
                    const pixel *top_sb_edge = NULL;
1753
3.58k
                    if (!(t->by & (f->sb_step - 1))) {
1754
2.66k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
2.66k
                        const int sby = t->by >> f->sb_shift;
1756
2.66k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
2.66k
                    }
1758
3.58k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
3.58k
                                                          (t->bx >> ss_hor) >
1760
3.58k
                                                              (ts->tiling.col_start >> ss_hor),
1761
3.58k
                                                          t->by >> ss_ver,
1762
3.58k
                                                          (t->by >> ss_ver) >
1763
3.58k
                                                              (ts->tiling.row_start >> ss_ver),
1764
3.58k
                                                          ts->tiling.col_end >> ss_hor,
1765
3.58k
                                                          ts->tiling.row_end >> ss_ver,
1766
3.58k
                                                          0, uvdst, f->cur.stride[1],
1767
3.58k
                                                          top_sb_edge, m,
1768
3.58k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
3.58k
                                                          HIGHBD_CALL_SUFFIX);
1770
3.58k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
3.58k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
3.58k
                                             HIGHBD_CALL_SUFFIX);
1773
3.58k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
3.58k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
3.58k
                }
1776
1.79k
            }
1777
88.8k
        }
1778
1779
112k
    skip_inter_chroma_pred: {}
1780
112k
        t->tl_4x4_filter = filter_2d;
1781
112k
    } else {
1782
19.3k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
19.3k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
19.3k
        int jnt_weight;
1786
19.3k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
19.3k
        const uint8_t *mask;
1788
1789
58.1k
        for (int i = 0; i < 2; i++) {
1790
38.7k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
38.7k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.95k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.95k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.95k
                if (res) return res;
1796
35.7k
            } else {
1797
35.7k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
35.7k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
35.7k
                if (res) return res;
1800
35.7k
            }
1801
38.7k
        }
1802
19.3k
        switch (b->comp_type) {
1803
14.6k
        case COMP_INTER_AVG:
1804
14.6k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
14.6k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
14.6k
            break;
1807
1.80k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.80k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.80k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.80k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.80k
            break;
1812
2.19k
        case COMP_INTER_SEG:
1813
2.19k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
2.19k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
2.19k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
2.19k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
2.19k
            mask = seg_mask;
1818
2.19k
            break;
1819
774
        case COMP_INTER_WEDGE:
1820
774
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
774
            dsp->mc.mask(dst, f->cur.stride[0],
1822
774
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
774
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
774
            if (has_chroma)
1825
670
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
774
            break;
1827
19.3k
        }
1828
1829
        // chroma
1830
45.1k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
90.3k
            for (int i = 0; i < 2; i++) {
1832
60.2k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
60.2k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
12.3k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
4.44k
                {
1836
4.44k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
4.44k
                                      b_dim, 1 + pl,
1838
4.44k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
4.44k
                    if (res) return res;
1840
55.7k
                } else {
1841
55.7k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
55.7k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
55.7k
                    if (res) return res;
1844
55.7k
                }
1845
60.2k
            }
1846
30.1k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
30.1k
            switch (b->comp_type) {
1848
23.0k
            case COMP_INTER_AVG:
1849
23.0k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
23.0k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
23.0k
                            HIGHBD_CALL_SUFFIX);
1852
23.0k
                break;
1853
2.03k
            case COMP_INTER_WEIGHTED_AVG:
1854
2.03k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
2.03k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
2.03k
                              HIGHBD_CALL_SUFFIX);
1857
2.03k
                break;
1858
1.34k
            case COMP_INTER_WEDGE:
1859
5.06k
            case COMP_INTER_SEG:
1860
5.06k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
5.06k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
5.06k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
5.06k
                             HIGHBD_CALL_SUFFIX);
1864
5.06k
                break;
1865
30.1k
            }
1866
30.1k
        }
1867
19.3k
    }
1868
1869
213k
    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
213k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
213k
    if (b->skip) {
1882
        // reset coef contexts
1883
100k
        BlockContext *const a = t->a;
1884
100k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
100k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
100k
        if (has_chroma) {
1887
54.4k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
54.4k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
54.4k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
54.4k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
54.4k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
54.4k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
54.4k
        }
1894
100k
        return 0;
1895
100k
    }
1896
1897
112k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
112k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
112k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
233k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
243k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
123k
            int y_off = !!init_y, y;
1905
123k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
261k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
138k
                 y += ytx->h, y_off++)
1908
138k
            {
1909
138k
                int x, x_off = !!init_x;
1910
340k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
202k
                     x += ytx->w, x_off++)
1912
202k
                {
1913
202k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
202k
                                   x_off, y_off, &dst[x * 4]);
1915
202k
                    t->bx += ytx->w;
1916
202k
                }
1917
138k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
138k
                t->bx -= x;
1919
138k
                t->by += ytx->h;
1920
138k
            }
1921
123k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
123k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
288k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
192k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
192k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
192k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
421k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
229k
                {
1931
229k
                    int x;
1932
229k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
590k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
360k
                    {
1935
360k
                        coef *cf;
1936
360k
                        int eob;
1937
360k
                        enum TxfmType txtp;
1938
360k
                        if (t->frame_thread.pass) {
1939
360k
                            const int p = t->frame_thread.pass & 1;
1940
360k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
360k
                            cf = ts->frame_thread[p].cf;
1942
360k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
360k
                            eob  = cbi >> 5;
1944
360k
                            txtp = cbi & 0x1f;
1945
360k
                        } 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
360k
                        if (eob >= 0) {
1964
131k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
131k
                            dsp->itx.itxfm_add[b->uvtx]
1967
131k
                                              [txtp](&uvdst[4 * x],
1968
131k
                                                     f->cur.stride[1],
1969
131k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
131k
                            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
131k
                        }
1974
360k
                        t->bx += uvtx->w << ss_hor;
1975
360k
                    }
1976
229k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
229k
                    t->bx -= x << ss_hor;
1978
229k
                    t->by += uvtx->h << ss_ver;
1979
229k
                }
1980
192k
                t->by -= y << ss_ver;
1981
192k
            }
1982
123k
        }
1983
120k
    }
1984
112k
    return 0;
1985
213k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
142k
{
1560
142k
    Dav1dTileState *const ts = t->ts;
1561
142k
    const Dav1dFrameContext *const f = t->f;
1562
142k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
142k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
142k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
142k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
142k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
142k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
142k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
142k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
142k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
98.1k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
93.8k
                           (bh4 > ss_ver || t->by & 1);
1573
142k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
142k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
142k
    int res;
1576
1577
    // prediction
1578
142k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
142k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
142k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
142k
    const ptrdiff_t uvdstoff =
1582
142k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
142k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
57.9k
        assert(!f->frame_hdr->super_res.enabled);
1586
57.9k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
57.9k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
57.9k
        if (res) return res;
1589
57.9k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
33.2k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
33.2k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
33.2k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
33.2k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
33.2k
            if (res) return res;
1595
33.2k
        }
1596
84.5k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
75.5k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
75.5k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
75.5k
        if (imin(bw4, bh4) > 1 &&
1601
51.9k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
50.5k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.78k
        {
1604
2.78k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.78k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.78k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.78k
            if (res) return res;
1608
72.7k
        } else {
1609
72.7k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
72.7k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
72.7k
            if (res) return res;
1612
72.7k
            if (b->motion_mode == MM_OBMC) {
1613
13.4k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
13.4k
                if (res) return res;
1615
13.4k
            }
1616
72.7k
        }
1617
75.5k
        if (b->interintra_type) {
1618
1.07k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
1.07k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
942
                                   SMOOTH_PRED : b->interintra_mode;
1621
1.07k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
1.07k
            int angle = 0;
1623
1.07k
            const pixel *top_sb_edge = NULL;
1624
1.07k
            if (!(t->by & (f->sb_step - 1))) {
1625
729
                top_sb_edge = f->ipred_edge[0];
1626
729
                const int sby = t->by >> f->sb_shift;
1627
729
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
729
            }
1629
1.07k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
1.07k
                                                  t->by, t->by > ts->tiling.row_start,
1631
1.07k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
1.07k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
1.07k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
1.07k
                                                  HIGHBD_CALL_SUFFIX);
1635
1.07k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
1.07k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
1.07k
                                     HIGHBD_CALL_SUFFIX);
1638
1.07k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
1.07k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
1.07k
        }
1641
1642
75.5k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
66.0k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
66.0k
        refmvs_block *const *r;
1647
66.0k
        if (is_sub8x8) {
1648
3.81k
            assert(ss_hor == 1);
1649
3.81k
            r = &t->rt.r[(t->by & 31) + 5];
1650
3.81k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
3.81k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
3.81k
            if (bw4 == 1 && bh4 == ss_ver)
1653
460
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
3.81k
        }
1655
1656
        // chroma prediction
1657
66.0k
        if (is_sub8x8) {
1658
3.76k
            assert(ss_hor == 1);
1659
3.76k
            ptrdiff_t h_off = 0, v_off = 0;
1660
3.76k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.35k
                for (int pl = 0; pl < 2; pl++) {
1662
902
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
902
                             NULL, f->cur.stride[1],
1664
902
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
902
                             r[-1][t->bx - 1].mv.mv[0],
1666
902
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
902
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
902
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
902
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
902
                    if (res) return res;
1671
902
                }
1672
451
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
451
                h_off = 2;
1674
451
            }
1675
3.76k
            if (bw4 == 1) {
1676
1.94k
                const enum Filter2d left_filter_2d =
1677
1.94k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
5.82k
                for (int pl = 0; pl < 2; pl++) {
1679
3.88k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
3.88k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
3.88k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
3.88k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
3.88k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
3.88k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
3.88k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
3.88k
                    if (res) return res;
1687
3.88k
                }
1688
1.94k
                h_off = 2;
1689
1.94k
            }
1690
3.76k
            if (bh4 == ss_ver) {
1691
2.27k
                const enum Filter2d top_filter_2d =
1692
2.27k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
6.83k
                for (int pl = 0; pl < 2; pl++) {
1694
4.55k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
4.55k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
4.55k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
4.55k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
4.55k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
4.55k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
4.55k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
4.55k
                    if (res) return res;
1702
4.55k
                }
1703
2.27k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
2.27k
            }
1705
11.3k
            for (int pl = 0; pl < 2; pl++) {
1706
7.53k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
7.53k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
7.53k
                         refp, b->ref[0], filter_2d);
1709
7.53k
                if (res) return res;
1710
7.53k
            }
1711
62.2k
        } else {
1712
62.2k
            if (imin(cbw4, cbh4) > 1 &&
1713
37.8k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
36.6k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.63k
            {
1716
7.91k
                for (int pl = 0; pl < 2; pl++) {
1717
5.27k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
5.27k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
5.27k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
5.27k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
5.27k
                    if (res) return res;
1722
5.27k
                }
1723
59.6k
            } else {
1724
178k
                for (int pl = 0; pl < 2; pl++) {
1725
119k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
119k
                             NULL, f->cur.stride[1],
1727
119k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
119k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
119k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
119k
                    if (res) return res;
1731
119k
                    if (b->motion_mode == MM_OBMC) {
1732
25.7k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
25.7k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
25.7k
                        if (res) return res;
1735
25.7k
                    }
1736
119k
                }
1737
59.6k
            }
1738
62.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
911
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
2.73k
                for (int pl = 0; pl < 2; pl++) {
1745
1.82k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.82k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.82k
                    enum IntraPredMode m =
1748
1.82k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.63k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.82k
                    int angle = 0;
1751
1.82k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.82k
                    const pixel *top_sb_edge = NULL;
1753
1.82k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.18k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.18k
                        const int sby = t->by >> f->sb_shift;
1756
1.18k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.18k
                    }
1758
1.82k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.82k
                                                          (t->bx >> ss_hor) >
1760
1.82k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.82k
                                                          t->by >> ss_ver,
1762
1.82k
                                                          (t->by >> ss_ver) >
1763
1.82k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.82k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.82k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.82k
                                                          0, uvdst, f->cur.stride[1],
1767
1.82k
                                                          top_sb_edge, m,
1768
1.82k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.82k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.82k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.82k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.82k
                                             HIGHBD_CALL_SUFFIX);
1773
1.82k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.82k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.82k
                }
1776
911
            }
1777
62.2k
        }
1778
1779
75.5k
    skip_inter_chroma_pred: {}
1780
75.5k
        t->tl_4x4_filter = filter_2d;
1781
75.5k
    } else {
1782
8.98k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
8.98k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
8.98k
        int jnt_weight;
1786
8.98k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
8.98k
        const uint8_t *mask;
1788
1789
26.9k
        for (int i = 0; i < 2; i++) {
1790
17.9k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
17.9k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.92k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.92k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.92k
                if (res) return res;
1796
16.0k
            } else {
1797
16.0k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
16.0k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
16.0k
                if (res) return res;
1800
16.0k
            }
1801
17.9k
        }
1802
8.98k
        switch (b->comp_type) {
1803
7.17k
        case COMP_INTER_AVG:
1804
7.17k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
7.17k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
7.17k
            break;
1807
577
        case COMP_INTER_WEIGHTED_AVG:
1808
577
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
577
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
577
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
577
            break;
1812
904
        case COMP_INTER_SEG:
1813
904
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
904
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
904
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
904
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
904
            mask = seg_mask;
1818
904
            break;
1819
331
        case COMP_INTER_WEDGE:
1820
331
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
331
            dsp->mc.mask(dst, f->cur.stride[0],
1822
331
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
331
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
331
            if (has_chroma)
1825
276
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
331
            break;
1827
8.98k
        }
1828
1829
        // chroma
1830
20.4k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
40.8k
            for (int i = 0; i < 2; i++) {
1832
27.2k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
27.2k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
6.18k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
2.97k
                {
1836
2.97k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
2.97k
                                      b_dim, 1 + pl,
1838
2.97k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
2.97k
                    if (res) return res;
1840
24.2k
                } else {
1841
24.2k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
24.2k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
24.2k
                    if (res) return res;
1844
24.2k
                }
1845
27.2k
            }
1846
13.6k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
13.6k
            switch (b->comp_type) {
1848
10.8k
            case COMP_INTER_AVG:
1849
10.8k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
10.8k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
10.8k
                            HIGHBD_CALL_SUFFIX);
1852
10.8k
                break;
1853
578
            case COMP_INTER_WEIGHTED_AVG:
1854
578
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
578
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
578
                              HIGHBD_CALL_SUFFIX);
1857
578
                break;
1858
552
            case COMP_INTER_WEDGE:
1859
2.19k
            case COMP_INTER_SEG:
1860
2.19k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.19k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.19k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.19k
                             HIGHBD_CALL_SUFFIX);
1864
2.19k
                break;
1865
13.6k
            }
1866
13.6k
        }
1867
8.98k
    }
1868
1869
142k
    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
142k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
142k
    if (b->skip) {
1882
        // reset coef contexts
1883
80.4k
        BlockContext *const a = t->a;
1884
80.4k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
80.4k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
80.4k
        if (has_chroma) {
1887
41.2k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
41.2k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
41.2k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
41.2k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
41.2k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
41.2k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
41.2k
        }
1894
80.4k
        return 0;
1895
80.4k
    }
1896
1897
61.9k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
61.9k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
61.9k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
127k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
133k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
67.5k
            int y_off = !!init_y, y;
1905
67.5k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
145k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
77.9k
                 y += ytx->h, y_off++)
1908
77.9k
            {
1909
77.9k
                int x, x_off = !!init_x;
1910
200k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
122k
                     x += ytx->w, x_off++)
1912
122k
                {
1913
122k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
122k
                                   x_off, y_off, &dst[x * 4]);
1915
122k
                    t->bx += ytx->w;
1916
122k
                }
1917
77.9k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
77.9k
                t->bx -= x;
1919
77.9k
                t->by += ytx->h;
1920
77.9k
            }
1921
67.5k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
67.5k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
159k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
106k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
106k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
106k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
238k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
131k
                {
1931
131k
                    int x;
1932
131k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
353k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
222k
                    {
1935
222k
                        coef *cf;
1936
222k
                        int eob;
1937
222k
                        enum TxfmType txtp;
1938
222k
                        if (t->frame_thread.pass) {
1939
222k
                            const int p = t->frame_thread.pass & 1;
1940
222k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
222k
                            cf = ts->frame_thread[p].cf;
1942
222k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
222k
                            eob  = cbi >> 5;
1944
222k
                            txtp = cbi & 0x1f;
1945
222k
                        } 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
222k
                        if (eob >= 0) {
1964
86.9k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
86.9k
                            dsp->itx.itxfm_add[b->uvtx]
1967
86.9k
                                              [txtp](&uvdst[4 * x],
1968
86.9k
                                                     f->cur.stride[1],
1969
86.9k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
86.9k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
86.9k
                        }
1974
222k
                        t->bx += uvtx->w << ss_hor;
1975
222k
                    }
1976
131k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
131k
                    t->bx -= x << ss_hor;
1978
131k
                    t->by += uvtx->h << ss_ver;
1979
131k
                }
1980
106k
                t->by -= y << ss_ver;
1981
106k
            }
1982
67.5k
        }
1983
65.9k
    }
1984
61.9k
    return 0;
1985
142k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
71.0k
{
1560
71.0k
    Dav1dTileState *const ts = t->ts;
1561
71.0k
    const Dav1dFrameContext *const f = t->f;
1562
71.0k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
71.0k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
71.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
71.0k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
71.0k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
71.0k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
71.0k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
71.0k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
71.0k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
57.0k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
54.6k
                           (bh4 > ss_ver || t->by & 1);
1573
71.0k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
71.0k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
71.0k
    int res;
1576
1577
    // prediction
1578
71.0k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
71.0k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
71.0k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
71.0k
    const ptrdiff_t uvdstoff =
1582
71.0k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
71.0k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
23.9k
        assert(!f->frame_hdr->super_res.enabled);
1586
23.9k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
23.9k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
23.9k
        if (res) return res;
1589
47.8k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
31.8k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
31.8k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
31.8k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
31.8k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
31.8k
            if (res) return res;
1595
31.8k
        }
1596
47.1k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
36.7k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
36.7k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
36.7k
        if (imin(bw4, bh4) > 1 &&
1601
20.3k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
19.6k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.25k
        {
1604
1.25k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.25k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.25k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.25k
            if (res) return res;
1608
35.4k
        } else {
1609
35.4k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
35.4k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
35.4k
            if (res) return res;
1612
35.4k
            if (b->motion_mode == MM_OBMC) {
1613
4.52k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
4.52k
                if (res) return res;
1615
4.52k
            }
1616
35.4k
        }
1617
36.7k
        if (b->interintra_type) {
1618
1.09k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
1.09k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
848
                                   SMOOTH_PRED : b->interintra_mode;
1621
1.09k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
1.09k
            int angle = 0;
1623
1.09k
            const pixel *top_sb_edge = NULL;
1624
1.09k
            if (!(t->by & (f->sb_step - 1))) {
1625
890
                top_sb_edge = f->ipred_edge[0];
1626
890
                const int sby = t->by >> f->sb_shift;
1627
890
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
890
            }
1629
1.09k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
1.09k
                                                  t->by, t->by > ts->tiling.row_start,
1631
1.09k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
1.09k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
1.09k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
1.09k
                                                  HIGHBD_CALL_SUFFIX);
1635
1.09k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
1.09k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
1.09k
                                     HIGHBD_CALL_SUFFIX);
1638
1.09k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
1.09k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
1.09k
        }
1641
1642
36.7k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
27.9k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
27.9k
        refmvs_block *const *r;
1647
27.9k
        if (is_sub8x8) {
1648
1.41k
            assert(ss_hor == 1);
1649
1.41k
            r = &t->rt.r[(t->by & 31) + 5];
1650
1.41k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
1.41k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
1.41k
            if (bw4 == 1 && bh4 == ss_ver)
1653
204
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
1.41k
        }
1655
1656
        // chroma prediction
1657
27.9k
        if (is_sub8x8) {
1658
1.33k
            assert(ss_hor == 1);
1659
1.33k
            ptrdiff_t h_off = 0, v_off = 0;
1660
1.33k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
552
                for (int pl = 0; pl < 2; pl++) {
1662
368
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
368
                             NULL, f->cur.stride[1],
1664
368
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
368
                             r[-1][t->bx - 1].mv.mv[0],
1666
368
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
368
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
368
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
368
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
368
                    if (res) return res;
1671
368
                }
1672
184
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
184
                h_off = 2;
1674
184
            }
1675
1.33k
            if (bw4 == 1) {
1676
735
                const enum Filter2d left_filter_2d =
1677
735
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
2.20k
                for (int pl = 0; pl < 2; pl++) {
1679
1.47k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
1.47k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
1.47k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
1.47k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
1.47k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
1.47k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
1.47k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
1.47k
                    if (res) return res;
1687
1.47k
                }
1688
735
                h_off = 2;
1689
735
            }
1690
1.33k
            if (bh4 == ss_ver) {
1691
779
                const enum Filter2d top_filter_2d =
1692
779
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
2.33k
                for (int pl = 0; pl < 2; pl++) {
1694
1.55k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
1.55k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
1.55k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
1.55k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
1.55k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
1.55k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
1.55k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
1.55k
                    if (res) return res;
1702
1.55k
                }
1703
779
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
779
            }
1705
3.99k
            for (int pl = 0; pl < 2; pl++) {
1706
2.66k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
2.66k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
2.66k
                         refp, b->ref[0], filter_2d);
1709
2.66k
                if (res) return res;
1710
2.66k
            }
1711
26.6k
        } else {
1712
26.6k
            if (imin(cbw4, cbh4) > 1 &&
1713
12.7k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
12.0k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.13k
            {
1716
3.41k
                for (int pl = 0; pl < 2; pl++) {
1717
2.27k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
2.27k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
2.27k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
2.27k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
2.27k
                    if (res) return res;
1722
2.27k
                }
1723
25.5k
            } else {
1724
76.5k
                for (int pl = 0; pl < 2; pl++) {
1725
51.0k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
51.0k
                             NULL, f->cur.stride[1],
1727
51.0k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
51.0k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
51.0k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
51.0k
                    if (res) return res;
1731
51.0k
                    if (b->motion_mode == MM_OBMC) {
1732
6.95k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
6.95k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
6.95k
                        if (res) return res;
1735
6.95k
                    }
1736
51.0k
                }
1737
25.5k
            }
1738
26.6k
            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
881
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
2.64k
                for (int pl = 0; pl < 2; pl++) {
1745
1.76k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.76k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.76k
                    enum IntraPredMode m =
1748
1.76k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.35k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.76k
                    int angle = 0;
1751
1.76k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.76k
                    const pixel *top_sb_edge = NULL;
1753
1.76k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.48k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.48k
                        const int sby = t->by >> f->sb_shift;
1756
1.48k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.48k
                    }
1758
1.76k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.76k
                                                          (t->bx >> ss_hor) >
1760
1.76k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.76k
                                                          t->by >> ss_ver,
1762
1.76k
                                                          (t->by >> ss_ver) >
1763
1.76k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.76k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.76k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.76k
                                                          0, uvdst, f->cur.stride[1],
1767
1.76k
                                                          top_sb_edge, m,
1768
1.76k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.76k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.76k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.76k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.76k
                                             HIGHBD_CALL_SUFFIX);
1773
1.76k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.76k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.76k
                }
1776
881
            }
1777
26.6k
        }
1778
1779
36.7k
    skip_inter_chroma_pred: {}
1780
36.7k
        t->tl_4x4_filter = filter_2d;
1781
36.7k
    } else {
1782
10.3k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
10.3k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
10.3k
        int jnt_weight;
1786
10.3k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
10.3k
        const uint8_t *mask;
1788
1789
31.1k
        for (int i = 0; i < 2; i++) {
1790
20.7k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
20.7k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.03k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.03k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.03k
                if (res) return res;
1796
19.7k
            } else {
1797
19.7k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
19.7k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
19.7k
                if (res) return res;
1800
19.7k
            }
1801
20.7k
        }
1802
10.3k
        switch (b->comp_type) {
1803
7.43k
        case COMP_INTER_AVG:
1804
7.43k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
7.43k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
7.43k
            break;
1807
1.22k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.22k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.22k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.22k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.22k
            break;
1812
1.28k
        case COMP_INTER_SEG:
1813
1.28k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.28k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.28k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.28k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.28k
            mask = seg_mask;
1818
1.28k
            break;
1819
443
        case COMP_INTER_WEDGE:
1820
443
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
443
            dsp->mc.mask(dst, f->cur.stride[0],
1822
443
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
443
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
443
            if (has_chroma)
1825
394
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
443
            break;
1827
10.3k
        }
1828
1829
        // chroma
1830
24.7k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
49.4k
            for (int i = 0; i < 2; i++) {
1832
32.9k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
32.9k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
6.13k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.47k
                {
1836
1.47k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.47k
                                      b_dim, 1 + pl,
1838
1.47k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.47k
                    if (res) return res;
1840
31.4k
                } else {
1841
31.4k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
31.4k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
31.4k
                    if (res) return res;
1844
31.4k
                }
1845
32.9k
            }
1846
16.4k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
16.4k
            switch (b->comp_type) {
1848
12.1k
            case COMP_INTER_AVG:
1849
12.1k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
12.1k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
12.1k
                            HIGHBD_CALL_SUFFIX);
1852
12.1k
                break;
1853
1.45k
            case COMP_INTER_WEIGHTED_AVG:
1854
1.45k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
1.45k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
1.45k
                              HIGHBD_CALL_SUFFIX);
1857
1.45k
                break;
1858
788
            case COMP_INTER_WEDGE:
1859
2.86k
            case COMP_INTER_SEG:
1860
2.86k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.86k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.86k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.86k
                             HIGHBD_CALL_SUFFIX);
1864
2.86k
                break;
1865
16.4k
            }
1866
16.4k
        }
1867
10.3k
    }
1868
1869
71.0k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
71.0k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
71.0k
    if (b->skip) {
1882
        // reset coef contexts
1883
20.2k
        BlockContext *const a = t->a;
1884
20.2k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
20.2k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
20.2k
        if (has_chroma) {
1887
13.1k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
13.1k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
13.1k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
13.1k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
13.1k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
13.1k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
13.1k
        }
1894
20.2k
        return 0;
1895
20.2k
    }
1896
1897
50.8k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
50.8k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
50.8k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
105k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
110k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
55.7k
            int y_off = !!init_y, y;
1905
55.7k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
116k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
60.3k
                 y += ytx->h, y_off++)
1908
60.3k
            {
1909
60.3k
                int x, x_off = !!init_x;
1910
140k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
80.5k
                     x += ytx->w, x_off++)
1912
80.5k
                {
1913
80.5k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
80.5k
                                   x_off, y_off, &dst[x * 4]);
1915
80.5k
                    t->bx += ytx->w;
1916
80.5k
                }
1917
60.3k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
60.3k
                t->bx -= x;
1919
60.3k
                t->by += ytx->h;
1920
60.3k
            }
1921
55.7k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
55.7k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
128k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
85.5k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
85.5k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
85.5k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
183k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
97.6k
                {
1931
97.6k
                    int x;
1932
97.6k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
236k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
138k
                    {
1935
138k
                        coef *cf;
1936
138k
                        int eob;
1937
138k
                        enum TxfmType txtp;
1938
138k
                        if (t->frame_thread.pass) {
1939
138k
                            const int p = t->frame_thread.pass & 1;
1940
138k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
138k
                            cf = ts->frame_thread[p].cf;
1942
138k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
138k
                            eob  = cbi >> 5;
1944
138k
                            txtp = cbi & 0x1f;
1945
138k
                        } 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
138k
                        if (eob >= 0) {
1964
44.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
44.7k
                            dsp->itx.itxfm_add[b->uvtx]
1967
44.7k
                                              [txtp](&uvdst[4 * x],
1968
44.7k
                                                     f->cur.stride[1],
1969
44.7k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
44.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
44.7k
                        }
1974
138k
                        t->bx += uvtx->w << ss_hor;
1975
138k
                    }
1976
97.6k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
97.6k
                    t->bx -= x << ss_hor;
1978
97.6k
                    t->by += uvtx->h << ss_ver;
1979
97.6k
                }
1980
85.5k
                t->by -= y << ss_ver;
1981
85.5k
            }
1982
55.7k
        }
1983
54.7k
    }
1984
50.8k
    return 0;
1985
71.0k
}
1986
1987
90.8k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
90.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
90.8k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
90.8k
    const int y = sby * f->sb_step * 4;
1994
90.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
90.8k
    pixel *const p[3] = {
1996
90.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
90.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
90.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
90.8k
    };
2000
90.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
90.8k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
90.8k
                                        f->lf.start_of_tile_row[sby]);
2003
90.8k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
53.6k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
53.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
53.6k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
53.6k
    const int y = sby * f->sb_step * 4;
1994
53.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
53.6k
    pixel *const p[3] = {
1996
53.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
53.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
53.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
53.6k
    };
2000
53.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
53.6k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
53.6k
                                        f->lf.start_of_tile_row[sby]);
2003
53.6k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
37.1k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
37.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
37.1k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
37.1k
    const int y = sby * f->sb_step * 4;
1994
37.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
37.1k
    pixel *const p[3] = {
1996
37.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
37.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
37.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
37.1k
    };
2000
37.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
37.1k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
37.1k
                                        f->lf.start_of_tile_row[sby]);
2003
37.1k
}
2004
2005
98.9k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
98.9k
    const int y = sby * f->sb_step * 4;
2007
98.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
98.9k
    pixel *const p[3] = {
2009
98.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
98.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
98.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
98.9k
    };
2013
98.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
98.9k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
98.9k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
90.6k
    {
2017
90.6k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
90.6k
    }
2019
98.9k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
84.7k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
84.7k
    }
2023
98.9k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
59.5k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
59.5k
    const int y = sby * f->sb_step * 4;
2007
59.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
59.5k
    pixel *const p[3] = {
2009
59.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
59.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
59.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
59.5k
    };
2013
59.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
59.5k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
59.5k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
53.5k
    {
2017
53.5k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
53.5k
    }
2019
59.5k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
52.2k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
52.2k
    }
2023
59.5k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
39.4k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
39.4k
    const int y = sby * f->sb_step * 4;
2007
39.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
39.4k
    pixel *const p[3] = {
2009
39.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
39.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
39.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
39.4k
    };
2013
39.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
39.4k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
39.4k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
37.1k
    {
2017
37.1k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
37.1k
    }
2019
39.4k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
32.5k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
32.5k
    }
2023
39.4k
}
2024
2025
56.0k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
56.0k
    const Dav1dFrameContext *const f = tc->f;
2027
56.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
56.0k
    const int sbsz = f->sb_step;
2029
56.0k
    const int y = sby * sbsz * 4;
2030
56.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
56.0k
    pixel *const p[3] = {
2032
56.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
56.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
56.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
56.0k
    };
2036
56.0k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
56.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
56.0k
    const int start = sby * sbsz;
2039
56.0k
    if (sby) {
2040
21.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
21.3k
        pixel *p_up[3] = {
2042
21.3k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
21.3k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
21.3k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
21.3k
        };
2046
21.3k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
21.3k
    }
2048
56.0k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
56.0k
    const int end = imin(start + n_blks, f->bh);
2050
56.0k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
56.0k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
36.3k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
36.3k
    const Dav1dFrameContext *const f = tc->f;
2027
36.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
36.3k
    const int sbsz = f->sb_step;
2029
36.3k
    const int y = sby * sbsz * 4;
2030
36.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
36.3k
    pixel *const p[3] = {
2032
36.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
36.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
36.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
36.3k
    };
2036
36.3k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
36.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
36.3k
    const int start = sby * sbsz;
2039
36.3k
    if (sby) {
2040
13.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
13.8k
        pixel *p_up[3] = {
2042
13.8k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
13.8k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
13.8k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
13.8k
        };
2046
13.8k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
13.8k
    }
2048
36.3k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
36.3k
    const int end = imin(start + n_blks, f->bh);
2050
36.3k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
36.3k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
19.6k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
19.6k
    const Dav1dFrameContext *const f = tc->f;
2027
19.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
19.6k
    const int sbsz = f->sb_step;
2029
19.6k
    const int y = sby * sbsz * 4;
2030
19.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
19.6k
    pixel *const p[3] = {
2032
19.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
19.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
19.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
19.6k
    };
2036
19.6k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
19.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
19.6k
    const int start = sby * sbsz;
2039
19.6k
    if (sby) {
2040
7.56k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
7.56k
        pixel *p_up[3] = {
2042
7.56k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
7.56k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
7.56k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
7.56k
        };
2046
7.56k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
7.56k
    }
2048
19.6k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
19.6k
    const int end = imin(start + n_blks, f->bh);
2050
19.6k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
19.6k
}
2052
2053
14.4k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
14.4k
    const int sbsz = f->sb_step;
2055
14.4k
    const int y = sby * sbsz * 4;
2056
14.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
14.4k
    const pixel *const p[3] = {
2058
14.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
14.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
14.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
14.4k
    };
2062
14.4k
    pixel *const sr_p[3] = {
2063
14.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
14.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
14.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
14.4k
    };
2067
14.4k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
51.2k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
36.7k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
36.7k
        const int h_start = 8 * !!sby >> ss_ver;
2071
36.7k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
36.7k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
36.7k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
36.7k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
36.7k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
36.7k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
36.7k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
36.7k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
36.7k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
36.7k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
36.7k
                          imin(img_h, h_end) + h_start, src_w,
2083
36.7k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
36.7k
                          HIGHBD_CALL_SUFFIX);
2085
36.7k
    }
2086
14.4k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
9.71k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
9.71k
    const int sbsz = f->sb_step;
2055
9.71k
    const int y = sby * sbsz * 4;
2056
9.71k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
9.71k
    const pixel *const p[3] = {
2058
9.71k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
9.71k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
9.71k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
9.71k
    };
2062
9.71k
    pixel *const sr_p[3] = {
2063
9.71k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
9.71k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
9.71k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
9.71k
    };
2067
9.71k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
35.7k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
26.0k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
26.0k
        const int h_start = 8 * !!sby >> ss_ver;
2071
26.0k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
26.0k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
26.0k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
26.0k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
26.0k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
26.0k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
26.0k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
26.0k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
26.0k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
26.0k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
26.0k
                          imin(img_h, h_end) + h_start, src_w,
2083
26.0k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
26.0k
                          HIGHBD_CALL_SUFFIX);
2085
26.0k
    }
2086
9.71k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
4.76k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
4.76k
    const int sbsz = f->sb_step;
2055
4.76k
    const int y = sby * sbsz * 4;
2056
4.76k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
4.76k
    const pixel *const p[3] = {
2058
4.76k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
4.76k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
4.76k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
4.76k
    };
2062
4.76k
    pixel *const sr_p[3] = {
2063
4.76k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
4.76k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
4.76k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
4.76k
    };
2067
4.76k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
15.4k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
10.7k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
10.7k
        const int h_start = 8 * !!sby >> ss_ver;
2071
10.7k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
10.7k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
10.7k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
10.7k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
10.7k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
10.7k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
10.7k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
10.7k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
10.7k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
10.7k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
10.7k
                          imin(img_h, h_end) + h_start, src_w,
2083
10.7k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
10.7k
                          HIGHBD_CALL_SUFFIX);
2085
10.7k
    }
2086
4.76k
}
2087
2088
63.8k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
63.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
63.8k
    const int y = sby * f->sb_step * 4;
2091
63.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
63.8k
    pixel *const sr_p[3] = {
2093
63.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
63.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
63.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
63.8k
    };
2097
63.8k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
63.8k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
39.3k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
39.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
39.3k
    const int y = sby * f->sb_step * 4;
2091
39.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
39.3k
    pixel *const sr_p[3] = {
2093
39.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
39.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
39.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
39.3k
    };
2097
39.3k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
39.3k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
24.5k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
24.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
24.5k
    const int y = sby * f->sb_step * 4;
2091
24.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
24.5k
    pixel *const sr_p[3] = {
2093
24.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
24.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
24.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
24.5k
    };
2097
24.5k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
24.5k
}
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
112k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
112k
    const Dav1dFrameContext *const f = t->f;
2113
112k
    Dav1dTileState *const ts = t->ts;
2114
112k
    const int sby = t->by >> f->sb_shift;
2115
112k
    const int sby_off = f->sb128w * 128 * sby;
2116
112k
    const int x_off = ts->tiling.col_start;
2117
2118
112k
    const pixel *const y =
2119
112k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
112k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
112k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
112k
               4 * (ts->tiling.col_end - x_off));
2123
2124
112k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
91.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
91.2k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
91.2k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
91.2k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
273k
        for (int pl = 1; pl <= 2; pl++)
2131
182k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
112k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
112k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
91.2k
    }
2135
112k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
66.6k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
66.6k
    const Dav1dFrameContext *const f = t->f;
2113
66.6k
    Dav1dTileState *const ts = t->ts;
2114
66.6k
    const int sby = t->by >> f->sb_shift;
2115
66.6k
    const int sby_off = f->sb128w * 128 * sby;
2116
66.6k
    const int x_off = ts->tiling.col_start;
2117
2118
66.6k
    const pixel *const y =
2119
66.6k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
66.6k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
66.6k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
66.6k
               4 * (ts->tiling.col_end - x_off));
2123
2124
66.6k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
56.0k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
56.0k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
56.0k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
56.0k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
168k
        for (int pl = 1; pl <= 2; pl++)
2131
112k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
112k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
112k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
56.0k
    }
2135
66.6k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
45.8k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
45.8k
    const Dav1dFrameContext *const f = t->f;
2113
45.8k
    Dav1dTileState *const ts = t->ts;
2114
45.8k
    const int sby = t->by >> f->sb_shift;
2115
45.8k
    const int sby_off = f->sb128w * 128 * sby;
2116
45.8k
    const int x_off = ts->tiling.col_start;
2117
2118
45.8k
    const pixel *const y =
2119
45.8k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
45.8k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
45.8k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
45.8k
               4 * (ts->tiling.col_end - x_off));
2123
2124
45.8k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
35.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
35.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
35.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
35.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
105k
        for (int pl = 1; pl <= 2; pl++)
2131
70.3k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
35.1k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
35.1k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
35.1k
    }
2135
45.8k
}
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
16.8k
{
2142
16.8k
    const Dav1dFrameContext *const f = t->f;
2143
16.8k
    pixel *const pal = t->frame_thread.pass ?
2144
16.8k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
16.8k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
16.8k
        bytefn(t->scratch.pal)[0];
2147
75.8k
    for (int x = 0; x < bw4; x++)
2148
58.9k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
68.7k
    for (int y = 0; y < bh4; y++)
2150
51.9k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
16.8k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
9.06k
{
2142
9.06k
    const Dav1dFrameContext *const f = t->f;
2143
9.06k
    pixel *const pal = t->frame_thread.pass ?
2144
9.06k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
9.06k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
9.06k
        bytefn(t->scratch.pal)[0];
2147
39.5k
    for (int x = 0; x < bw4; x++)
2148
30.4k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
35.7k
    for (int y = 0; y < bh4; y++)
2150
26.6k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
9.06k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
7.78k
{
2142
7.78k
    const Dav1dFrameContext *const f = t->f;
2143
7.78k
    pixel *const pal = t->frame_thread.pass ?
2144
7.78k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
7.78k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
7.78k
        bytefn(t->scratch.pal)[0];
2147
36.2k
    for (int x = 0; x < bw4; x++)
2148
28.5k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
33.0k
    for (int y = 0; y < bh4; y++)
2150
25.2k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
7.78k
}
2152
2153
void bytefn(dav1d_copy_pal_block_uv)(Dav1dTaskContext *const t,
2154
                                     const int bx4, const int by4,
2155
                                     const int bw4, const int bh4)
2156
2157
6.74k
{
2158
6.74k
    const Dav1dFrameContext *const f = t->f;
2159
6.74k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
6.74k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
6.74k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
6.74k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
20.2k
    for (int pl = 1; pl <= 2; pl++) {
2165
72.8k
        for (int x = 0; x < bw4; x++)
2166
59.3k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
68.1k
        for (int y = 0; y < bh4; y++)
2168
54.6k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
13.4k
    }
2170
6.74k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
4.02k
{
2158
4.02k
    const Dav1dFrameContext *const f = t->f;
2159
4.02k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
4.02k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
4.02k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
4.02k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
12.0k
    for (int pl = 1; pl <= 2; pl++) {
2165
43.5k
        for (int x = 0; x < bw4; x++)
2166
35.4k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
40.9k
        for (int y = 0; y < bh4; y++)
2168
32.9k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
8.05k
    }
2170
4.02k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
2.71k
{
2158
2.71k
    const Dav1dFrameContext *const f = t->f;
2159
2.71k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
2.71k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
2.71k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
2.71k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
8.14k
    for (int pl = 1; pl <= 2; pl++) {
2165
29.3k
        for (int x = 0; x < bw4; x++)
2166
23.8k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
27.2k
        for (int y = 0; y < bh4; y++)
2168
21.7k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
5.43k
    }
2170
2.71k
}
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
23.5k
{
2176
23.5k
    Dav1dTileState *const ts = t->ts;
2177
23.5k
    const Dav1dFrameContext *const f = t->f;
2178
23.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
23.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
23.5k
    pixel cache[16], used_cache[8];
2181
23.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
23.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
23.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
23.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
23.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
40.8k
    while (l_cache && a_cache) {
2190
17.2k
        if (*l < *a) {
2191
6.48k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
6.44k
                cache[n_cache++] = *l;
2193
6.48k
            l++;
2194
6.48k
            l_cache--;
2195
10.7k
        } else {
2196
10.7k
            if (*a == *l) {
2197
4.24k
                l++;
2198
4.24k
                l_cache--;
2199
4.24k
            }
2200
10.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
10.4k
                cache[n_cache++] = *a;
2202
10.7k
            a++;
2203
10.7k
            a_cache--;
2204
10.7k
        }
2205
17.2k
    }
2206
23.5k
    if (l_cache) {
2207
26.9k
        do {
2208
26.9k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
22.2k
                cache[n_cache++] = *l;
2210
26.9k
            l++;
2211
26.9k
        } while (--l_cache > 0);
2212
16.9k
    } else if (a_cache) {
2213
20.8k
        do {
2214
20.8k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
16.7k
                cache[n_cache++] = *a;
2216
20.8k
            a++;
2217
20.8k
        } while (--a_cache > 0);
2218
5.18k
    }
2219
2220
    // find reused cache entries
2221
23.5k
    int i = 0;
2222
72.7k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
49.1k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
24.6k
            used_cache[i++] = cache[n];
2225
23.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
23.5k
    pixel *const pal = t->frame_thread.pass ?
2229
23.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
23.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
23.5k
        bytefn(t->scratch.pal)[pl];
2232
23.5k
    if (i < pal_sz) {
2233
20.4k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
20.4k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
20.4k
        if (i < pal_sz) {
2237
18.3k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
18.3k
            const int max = (1 << bpc) - 1;
2239
2240
42.9k
            do {
2241
42.9k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
42.9k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
42.9k
                if (prev + !pl >= max) {
2244
23.3k
                    for (; i < pal_sz; i++)
2245
15.2k
                        pal[i] = max;
2246
8.15k
                    break;
2247
8.15k
                }
2248
34.8k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
34.8k
            } while (i < pal_sz);
2250
18.3k
        }
2251
2252
        // merge cache+new entries
2253
20.4k
        int n = 0, m = n_used_cache;
2254
115k
        for (i = 0; i < pal_sz; i++) {
2255
94.8k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
16.1k
                pal[i] = used_cache[n++];
2257
78.6k
            } else {
2258
78.6k
                assert(m < pal_sz);
2259
78.6k
                pal[i] = pal[m++];
2260
78.6k
            }
2261
94.8k
        }
2262
20.4k
    } else {
2263
3.14k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.14k
    }
2265
2266
23.5k
    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
23.5k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
13.0k
{
2176
13.0k
    Dav1dTileState *const ts = t->ts;
2177
13.0k
    const Dav1dFrameContext *const f = t->f;
2178
13.0k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
13.0k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
13.0k
    pixel cache[16], used_cache[8];
2181
13.0k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
13.0k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
13.0k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
13.0k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
13.0k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
23.9k
    while (l_cache && a_cache) {
2190
10.8k
        if (*l < *a) {
2191
4.08k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
4.05k
                cache[n_cache++] = *l;
2193
4.08k
            l++;
2194
4.08k
            l_cache--;
2195
6.81k
        } else {
2196
6.81k
            if (*a == *l) {
2197
2.64k
                l++;
2198
2.64k
                l_cache--;
2199
2.64k
            }
2200
6.81k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
6.64k
                cache[n_cache++] = *a;
2202
6.81k
            a++;
2203
6.81k
            a_cache--;
2204
6.81k
        }
2205
10.8k
    }
2206
13.0k
    if (l_cache) {
2207
15.3k
        do {
2208
15.3k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
12.6k
                cache[n_cache++] = *l;
2210
15.3k
            l++;
2211
15.3k
        } while (--l_cache > 0);
2212
9.25k
    } else if (a_cache) {
2213
11.2k
        do {
2214
11.2k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
9.00k
                cache[n_cache++] = *a;
2216
11.2k
            a++;
2217
11.2k
        } while (--a_cache > 0);
2218
2.88k
    }
2219
2220
    // find reused cache entries
2221
13.0k
    int i = 0;
2222
41.2k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
28.1k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
14.2k
            used_cache[i++] = cache[n];
2225
13.0k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
13.0k
    pixel *const pal = t->frame_thread.pass ?
2229
13.0k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
13.0k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
13.0k
        bytefn(t->scratch.pal)[pl];
2232
13.0k
    if (i < pal_sz) {
2233
11.2k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
11.2k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
11.2k
        if (i < pal_sz) {
2237
10.0k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
10.0k
            const int max = (1 << bpc) - 1;
2239
2240
23.3k
            do {
2241
23.3k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
23.3k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
23.3k
                if (prev + !pl >= max) {
2244
12.9k
                    for (; i < pal_sz; i++)
2245
8.47k
                        pal[i] = max;
2246
4.52k
                    break;
2247
4.52k
                }
2248
18.8k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
18.8k
            } while (i < pal_sz);
2250
10.0k
        }
2251
2252
        // merge cache+new entries
2253
11.2k
        int n = 0, m = n_used_cache;
2254
63.5k
        for (i = 0; i < pal_sz; i++) {
2255
52.2k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
9.20k
                pal[i] = used_cache[n++];
2257
43.0k
            } else {
2258
43.0k
                assert(m < pal_sz);
2259
43.0k
                pal[i] = pal[m++];
2260
43.0k
            }
2261
52.2k
        }
2262
11.2k
    } else {
2263
1.83k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.83k
    }
2265
2266
13.0k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
13.0k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
10.5k
{
2176
10.5k
    Dav1dTileState *const ts = t->ts;
2177
10.5k
    const Dav1dFrameContext *const f = t->f;
2178
10.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
10.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
10.5k
    pixel cache[16], used_cache[8];
2181
10.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
10.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
10.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
10.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
10.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
16.8k
    while (l_cache && a_cache) {
2190
6.31k
        if (*l < *a) {
2191
2.40k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.39k
                cache[n_cache++] = *l;
2193
2.40k
            l++;
2194
2.40k
            l_cache--;
2195
3.91k
        } else {
2196
3.91k
            if (*a == *l) {
2197
1.59k
                l++;
2198
1.59k
                l_cache--;
2199
1.59k
            }
2200
3.91k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
3.82k
                cache[n_cache++] = *a;
2202
3.91k
            a++;
2203
3.91k
            a_cache--;
2204
3.91k
        }
2205
6.31k
    }
2206
10.5k
    if (l_cache) {
2207
11.6k
        do {
2208
11.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
9.61k
                cache[n_cache++] = *l;
2210
11.6k
            l++;
2211
11.6k
        } while (--l_cache > 0);
2212
7.66k
    } else if (a_cache) {
2213
9.60k
        do {
2214
9.60k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
7.79k
                cache[n_cache++] = *a;
2216
9.60k
            a++;
2217
9.60k
        } while (--a_cache > 0);
2218
2.29k
    }
2219
2220
    // find reused cache entries
2221
10.5k
    int i = 0;
2222
31.4k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
20.9k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
10.3k
            used_cache[i++] = cache[n];
2225
10.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
10.5k
    pixel *const pal = t->frame_thread.pass ?
2229
10.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
10.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
10.5k
        bytefn(t->scratch.pal)[pl];
2232
10.5k
    if (i < pal_sz) {
2233
9.19k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
9.19k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
9.19k
        if (i < pal_sz) {
2237
8.32k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
8.32k
            const int max = (1 << bpc) - 1;
2239
2240
19.6k
            do {
2241
19.6k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
19.6k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
19.6k
                if (prev + !pl >= max) {
2244
10.3k
                    for (; i < pal_sz; i++)
2245
6.73k
                        pal[i] = max;
2246
3.63k
                    break;
2247
3.63k
                }
2248
16.0k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
16.0k
            } while (i < pal_sz);
2250
8.32k
        }
2251
2252
        // merge cache+new entries
2253
9.19k
        int n = 0, m = n_used_cache;
2254
51.7k
        for (i = 0; i < pal_sz; i++) {
2255
42.5k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
6.98k
                pal[i] = used_cache[n++];
2257
35.5k
            } else {
2258
35.5k
                assert(m < pal_sz);
2259
35.5k
                pal[i] = pal[m++];
2260
35.5k
            }
2261
42.5k
        }
2262
9.19k
    } else {
2263
1.31k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.31k
    }
2265
2266
10.5k
    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
10.5k
}
2277
2278
void bytefn(dav1d_read_pal_uv)(Dav1dTaskContext *const t, Av1Block *const b,
2279
                               const int sz_ctx, const int bx4, const int by4)
2280
6.74k
{
2281
6.74k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
6.74k
    Dav1dTileState *const ts = t->ts;
2285
6.74k
    const Dav1dFrameContext *const f = t->f;
2286
6.74k
    pixel *const pal = t->frame_thread.pass ?
2287
6.74k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
6.74k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
6.74k
        bytefn(t->scratch.pal)[2];
2290
6.74k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
6.74k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
3.44k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
3.44k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
3.44k
        const int max = (1 << bpc) - 1;
2295
14.3k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
10.9k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
10.9k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
10.9k
            prev = pal[i] = (prev + delta) & max;
2299
10.9k
        }
2300
3.44k
    } else {
2301
16.8k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
13.5k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
3.29k
    }
2304
6.74k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
6.74k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
4.02k
{
2281
4.02k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
4.02k
    Dav1dTileState *const ts = t->ts;
2285
4.02k
    const Dav1dFrameContext *const f = t->f;
2286
4.02k
    pixel *const pal = t->frame_thread.pass ?
2287
4.02k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
4.02k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
4.02k
        bytefn(t->scratch.pal)[2];
2290
4.02k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
4.02k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.08k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.08k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.08k
        const int max = (1 << bpc) - 1;
2295
8.80k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
6.72k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
6.72k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
6.72k
            prev = pal[i] = (prev + delta) & max;
2299
6.72k
        }
2300
2.08k
    } else {
2301
10.1k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
8.15k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.94k
    }
2304
4.02k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
4.02k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
2.71k
{
2281
2.71k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
2.71k
    Dav1dTileState *const ts = t->ts;
2285
2.71k
    const Dav1dFrameContext *const f = t->f;
2286
2.71k
    pixel *const pal = t->frame_thread.pass ?
2287
2.71k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
2.71k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
2.71k
        bytefn(t->scratch.pal)[2];
2290
2.71k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
2.71k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.36k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.36k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.36k
        const int max = (1 << bpc) - 1;
2295
5.58k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
4.21k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
4.21k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
4.21k
            prev = pal[i] = (prev + delta) & max;
2299
4.21k
        }
2300
1.36k
    } else {
2301
6.76k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
5.42k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.34k
    }
2304
2.71k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
2.71k
}