Coverage Report

Created: 2026-06-15 06:24

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