Coverage Report

Created: 2026-08-31 06:20

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