Coverage Report

Created: 2026-06-15 06:22

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