Coverage Report

Created: 2026-08-13 07:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/recon_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018-2021, VideoLAN and dav1d authors
3
 * Copyright © 2018, Two Orioles, LLC
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright notice, this
10
 *    list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright notice,
13
 *    this list of conditions and the following disclaimer in the documentation
14
 *    and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
28
#include "config.h"
29
30
#include <string.h>
31
#include <stdio.h>
32
33
#include "common/attributes.h"
34
#include "common/bitdepth.h"
35
#include "common/dump.h"
36
#include "common/frame.h"
37
#include "common/intops.h"
38
39
#include "src/cdef_apply.h"
40
#include "src/ctx.h"
41
#include "src/ipred_prepare.h"
42
#include "src/lf_apply.h"
43
#include "src/lr_apply.h"
44
#include "src/recon.h"
45
#include "src/scan.h"
46
#include "src/tables.h"
47
#include "src/wedge.h"
48
49
324k
static inline unsigned read_golomb(MsacContext *const msac) {
50
324k
    int len = 0;
51
324k
    unsigned val = 1;
52
53
631k
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
631k
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
324k
    return val - 1;
57
324k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
1.93M
{
66
1.93M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
1.93M
    if (chroma) {
69
1.13M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
1.13M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
1.13M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
581k
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
1.13M
        unsigned ca, cl;
74
75
1.13M
#define MERGE_CTX(dir, type, no_val) \
76
2.26M
        c##dir = *(const type *) dir != no_val; \
77
2.26M
        break
78
79
1.13M
        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
614k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
185k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
114k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
218k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
1.13M
        }
91
1.13M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
659k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
169k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
90.3k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
214k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
1.13M
        }
98
1.13M
#undef MERGE_CTX
99
100
1.13M
        return 7 + not_one_blk * 3 + ca + cl;
101
1.13M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
300k
        return 0;
103
503k
    } else {
104
503k
        unsigned la, ll;
105
106
503k
#define MERGE_CTX(dir, type, tx) \
107
1.00M
        if (tx == TX_64X64) { \
108
68.6k
            uint64_t tmp = *(const uint64_t *) dir; \
109
68.6k
            tmp |= *(const uint64_t *) &dir[8]; \
110
68.6k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
68.6k
        } else \
112
1.00M
            l##dir = *(const type *) dir; \
113
1.00M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
1.00M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
1.00M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
1.00M
        break
117
118
503k
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
297k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
76.1k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
89.0k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
6.56k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
34.3k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
503k
        }
126
503k
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
300k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
73.5k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
88.9k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
6.31k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
34.3k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
503k
        }
134
503k
#undef MERGE_CTX
135
136
503k
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
503k
    }
138
1.93M
}
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
835k
{
144
835k
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
835k
    int s;
146
147
835k
#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
835k
    __asm__("" : "+r"(mask), "+r"(mul));
151
835k
#endif
152
153
835k
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
381k
    case TX_4X4: {
156
381k
        int t = *(const uint8_t *) a >> 6;
157
381k
        t    += *(const uint8_t *) l >> 6;
158
381k
        s = t - 1 - 1;
159
381k
        break;
160
0
    }
161
84.7k
    case TX_8X8: {
162
84.7k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
84.7k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
84.7k
        t *= 0x04040404U;
165
84.7k
        s = (int) (t >> 24) - 2 - 2;
166
84.7k
        break;
167
0
    }
168
64.8k
    case TX_16X16: {
169
64.8k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
64.8k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
64.8k
        t *= (uint32_t) mul;
172
64.8k
        s = (int) (t >> 24) - 4 - 4;
173
64.8k
        break;
174
0
    }
175
67.3k
    case TX_32X32: {
176
67.3k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
67.3k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
67.3k
        t *= mul;
179
67.3k
        s = (int) (t >> 56) - 8 - 8;
180
67.3k
        break;
181
0
    }
182
30.6k
    case TX_64X64: {
183
30.6k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
30.6k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
30.6k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
30.6k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
30.6k
        t *= mul;
188
30.6k
        s = (int) (t >> 56) - 16 - 16;
189
30.6k
        break;
190
0
    }
191
28.0k
    case RTX_4X8: {
192
28.0k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
28.0k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
28.0k
        t *= 0x04040404U;
195
28.0k
        s = (int) (t >> 24) - 1 - 2;
196
28.0k
        break;
197
0
    }
198
41.8k
    case RTX_8X4: {
199
41.8k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
41.8k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
41.8k
        t *= 0x04040404U;
202
41.8k
        s = (int) (t >> 24) - 2 - 1;
203
41.8k
        break;
204
0
    }
205
19.0k
    case RTX_8X16: {
206
19.0k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
19.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
19.0k
        t = (t >> 6) * (uint32_t) mul;
209
19.0k
        s = (int) (t >> 24) - 2 - 4;
210
19.0k
        break;
211
0
    }
212
31.5k
    case RTX_16X8: {
213
31.5k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
31.5k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
31.5k
        t = (t >> 6) * (uint32_t) mul;
216
31.5k
        s = (int) (t >> 24) - 4 - 2;
217
31.5k
        break;
218
0
    }
219
8.49k
    case RTX_16X32: {
220
8.49k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
8.49k
        t         += *(const uint64_t *) l & mask;
222
8.49k
        t = (t >> 6) * mul;
223
8.49k
        s = (int) (t >> 56) - 4 - 8;
224
8.49k
        break;
225
0
    }
226
10.1k
    case RTX_32X16: {
227
10.1k
        uint64_t t = *(const uint64_t *) a & mask;
228
10.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
10.1k
        t = (t >> 6) * mul;
230
10.1k
        s = (int) (t >> 56) - 8 - 4;
231
10.1k
        break;
232
0
    }
233
6.70k
    case RTX_32X64: {
234
6.70k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
6.70k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
6.70k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
6.70k
        t *= mul;
238
6.70k
        s = (int) (t >> 56) - 8 - 16;
239
6.70k
        break;
240
0
    }
241
2.66k
    case RTX_64X32: {
242
2.66k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
2.66k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
2.66k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
2.66k
        t *= mul;
246
2.66k
        s = (int) (t >> 56) - 16 - 8;
247
2.66k
        break;
248
0
    }
249
12.9k
    case RTX_4X16: {
250
12.9k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
12.9k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
12.9k
        t = (t >> 6) * (uint32_t) mul;
253
12.9k
        s = (int) (t >> 24) - 1 - 4;
254
12.9k
        break;
255
0
    }
256
23.7k
    case RTX_16X4: {
257
23.7k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
23.7k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
23.7k
        t = (t >> 6) * (uint32_t) mul;
260
23.7k
        s = (int) (t >> 24) - 4 - 1;
261
23.7k
        break;
262
0
    }
263
7.31k
    case RTX_8X32: {
264
7.31k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
7.31k
        t         += *(const uint64_t *) l & mask;
266
7.31k
        t = (t >> 6) * mul;
267
7.31k
        s = (int) (t >> 56) - 2 - 8;
268
7.31k
        break;
269
0
    }
270
10.1k
    case RTX_32X8: {
271
10.1k
        uint64_t t = *(const uint64_t *) a & mask;
272
10.1k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
10.1k
        t = (t >> 6) * mul;
274
10.1k
        s = (int) (t >> 56) - 8 - 2;
275
10.1k
        break;
276
0
    }
277
1.88k
    case RTX_16X64: {
278
1.88k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
1.88k
        t         += *(const uint64_t *) &l[0] & mask;
280
1.88k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
1.88k
        t *= mul;
282
1.88k
        s = (int) (t >> 56) - 4 - 16;
283
1.88k
        break;
284
0
    }
285
1.90k
    case RTX_64X16: {
286
1.90k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
1.90k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
1.90k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
1.90k
        t *= mul;
290
1.90k
        s = (int) (t >> 56) - 16 - 4;
291
1.90k
        break;
292
0
    }
293
835k
    }
294
295
835k
    return (s != 0) + (s > 0);
296
835k
}
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
14.7M
{
305
14.7M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
14.7M
    unsigned offset;
307
14.7M
    if (tx_class == TX_CLASS_2D) {
308
13.5M
        mag += levels[1 * stride + 1];
309
13.5M
        *hi_mag = mag;
310
13.5M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
13.5M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
13.5M
    } else {
313
1.23M
        mag += levels[0 * stride + 2];
314
1.23M
        *hi_mag = mag;
315
1.23M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
1.23M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
1.23M
    }
318
14.7M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
14.7M
}
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.93M
{
328
1.93M
    Dav1dTileState *const ts = t->ts;
329
1.93M
    const int chroma = !!plane;
330
1.93M
    const Dav1dFrameContext *const f = t->f;
331
1.93M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
1.93M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
1.93M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
1.93M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
1.93M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
1.93M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
1.93M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
1.93M
    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.93M
    if (all_skip) {
346
934k
        *res_ctx = 0x40;
347
934k
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
934k
        return -1;
349
934k
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
1.00M
    if (lossless) {
353
367k
        assert(t_dim->max == TX_4X4);
354
367k
        *txtp = WHT_WHT;
355
635k
    } else if (t_dim->max + intra >= TX_64X64) {
356
141k
        *txtp = DCT_DCT;
357
493k
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
152k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
152k
                        get_uv_inter_txtp(t_dim, *txtp);
361
341k
    } 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
175
        *txtp = DCT_DCT;
366
341k
    } else {
367
341k
        unsigned idx;
368
341k
        if (intra) {
369
225k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
185k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
225k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
101k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
101k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
101k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
123k
            } else {
376
123k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
123k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
123k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
123k
            }
380
225k
            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
225k
        } else {
384
116k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
18.6k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
18.6k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
18.6k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
97.6k
            } else if (t_dim->min == TX_16X16) {
389
8.01k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
8.01k
                          ts->cdf.m.txtp_inter2, 11);
391
8.01k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
89.6k
            } else {
393
89.6k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
89.6k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
89.6k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
89.6k
            }
397
116k
            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
116k
        }
401
341k
    }
402
403
    // find end-of-block (eob)
404
1.00M
    int eob;
405
1.00M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
1.00M
    const int tx2dszctx = slw + slh;
407
1.00M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
1.00M
    const int is_1d = tx_class != TX_CLASS_2D;
409
1.00M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
1.00M
    case sz: { \
412
1.00M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
1.00M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
1.00M
        break; \
415
1.00M
    }
416
444k
    case_sz(0,   16,  8, [is_1d]);
417
91.0k
    case_sz(1,   32,  8, [is_1d]);
418
157k
    case_sz(2,   64,  8, [is_1d]);
419
66.6k
    case_sz(3,  128,  8, [is_1d]);
420
103k
    case_sz(4,  256, 16, [is_1d]);
421
26.0k
    case_sz(5,  512, 16,        );
422
114k
    case_sz(6, 1024, 16,        );
423
1.00M
#undef case_sz
424
1.00M
    }
425
1.00M
    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.00M
    if (eob > 1) {
429
574k
        const int eob_bin = eob - 2;
430
574k
        uint16_t *const eob_hi_bit_cdf =
431
574k
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
574k
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
574k
        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
574k
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
574k
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
574k
    }
440
1.00M
    assert(eob >= 0);
441
442
    // base tokens
443
1.00M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
1.00M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
1.00M
    unsigned rc, dc_tok;
446
447
1.00M
    if (eob) {
448
612k
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
612k
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
612k
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
612k
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
612k
        int tok = eob_tok + 1;
455
612k
        int level_tok = tok * 0x41;
456
612k
        unsigned mag;
457
458
612k
#define DECODE_COEFS_CLASS(tx_class) \
459
612k
        unsigned x, y; \
460
612k
        uint8_t *level; \
461
612k
        if (tx_class == TX_CLASS_2D) \
462
612k
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
612k
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
63.1k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
63.1k
        else /* tx_class == TX_CLASS_V */ \
467
63.1k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
612k
        if (dbg) \
469
612k
            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
612k
        if (eob_tok == 2) { \
472
8.54k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
8.54k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
8.54k
            level_tok = tok + (3 << 6); \
475
8.54k
            if (dbg) \
476
8.54k
                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
8.54k
        } \
480
612k
        cf[rc] = tok << 11; \
481
612k
        if (tx_class == TX_CLASS_2D) \
482
612k
            level = levels + rc; \
483
612k
        else \
484
612k
            level = levels + x * stride + y; \
485
612k
        *level = (uint8_t) level_tok; \
486
15.3M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
14.7M
            unsigned rc_i; \
488
14.7M
            if (tx_class == TX_CLASS_2D) \
489
14.7M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
14.7M
            else if (tx_class == TX_CLASS_H) \
491
1.17M
                x = i & mask, y = i >> shift, rc_i = i; \
492
1.17M
            else /* tx_class == TX_CLASS_V */ \
493
1.17M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
14.7M
            assert(x < 32 && y < 32); \
495
14.7M
            if (tx_class == TX_CLASS_2D) \
496
14.7M
                level = levels + rc_i; \
497
14.7M
            else \
498
14.7M
                level = levels + x * stride + y; \
499
14.7M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
14.7M
            if (tx_class == TX_CLASS_2D) \
501
14.7M
                y |= x; \
502
14.7M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
14.7M
            if (dbg) \
504
14.7M
                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
14.7M
            if (tok == 3) { \
507
1.32M
                mag &= 63; \
508
1.32M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
1.32M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
1.32M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
1.32M
                if (dbg) \
512
1.32M
                    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.32M
                *level = (uint8_t) (tok + (3 << 6)); \
516
1.32M
                cf[rc_i] = (tok << 11) | rc; \
517
1.32M
                rc = rc_i; \
518
13.4M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
13.4M
                tok *= 0x17ff41; \
521
13.4M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
13.4M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
13.4M
                if (tok) rc = rc_i; \
525
13.4M
                cf[rc_i] = tok; \
526
13.4M
            } \
527
14.7M
        } \
528
        /* dc */ \
529
612k
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
612k
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
612k
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
612k
        if (dbg) \
533
612k
            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
612k
        if (dc_tok == 3) { \
536
187k
            if (tx_class == TX_CLASS_2D) \
537
187k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
180k
                      levels[1 * stride + 1]; \
539
187k
            mag &= 63; \
540
187k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
187k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
187k
            if (dbg) \
543
187k
                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
187k
        } \
546
612k
        break
547
548
612k
        const uint16_t *scan;
549
612k
        switch (tx_class) {
550
549k
        case TX_CLASS_2D: {
551
549k
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
549k
            const uint8_t (*const lo_ctx_offsets)[5] =
553
549k
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
549k
            scan = dav1d_scans[tx];
555
549k
            const ptrdiff_t stride = 4 << slh;
556
549k
            const unsigned shift = slh + 2, shift2 = 0;
557
549k
            const unsigned mask = (4 << slh) - 1;
558
549k
            memset(levels, 0, stride * ((4 << slw) + 2));
559
549k
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
549k
        }
561
40.2k
        case TX_CLASS_H: {
562
40.2k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
40.2k
            const ptrdiff_t stride = 16;
564
40.2k
            const unsigned shift = slh + 2, shift2 = 0;
565
40.2k
            const unsigned mask = (4 << slh) - 1;
566
40.2k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
40.2k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
40.2k
        }
569
22.9k
        case TX_CLASS_V: {
570
22.9k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
22.9k
            const ptrdiff_t stride = 16;
572
22.9k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
22.9k
            const unsigned mask = (4 << slw) - 1;
574
22.9k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
22.9k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
22.9k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
612k
        }
580
612k
    } else { // dc-only
581
389k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
389k
        dc_tok = 1 + tok_br;
583
389k
        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
389k
        if (tok_br == 2) {
587
13.1k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
13.1k
            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
13.1k
        }
592
389k
        rc = 0;
593
389k
    }
594
595
    // residual and sign
596
1.00M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
1.00M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
1.00M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
1.00M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
1.00M
    unsigned cul_level, dc_sign_level;
601
602
1.00M
    if (!dc_tok) {
603
167k
        cul_level = 0;
604
167k
        dc_sign_level = 1 << 6;
605
167k
        if (qm_tbl) goto ac_qm;
606
114k
        goto ac_noqm;
607
167k
    }
608
609
835k
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
835k
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
835k
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
835k
    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
835k
    int dc_dq = dq_tbl[0];
617
835k
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
835k
    if (qm_tbl) {
620
292k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
292k
        if (dc_tok == 15) {
623
6.49k
            dc_tok = read_golomb(&ts->msac) + 15;
624
6.49k
            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.49k
            dc_tok &= 0xfffff;
629
6.49k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
286k
        } else {
631
286k
            dc_dq *= dc_tok;
632
286k
            assert(dc_dq <= 0xffffff);
633
286k
        }
634
292k
        cul_level = dc_tok;
635
292k
        dc_dq >>= dq_shift;
636
292k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
292k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
400k
        if (rc) ac_qm: {
640
400k
            const unsigned ac_dq = dq_tbl[1];
641
2.86M
            do {
642
2.86M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
2.86M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
2.86M
                const unsigned rc_tok = cf[rc];
646
2.86M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
2.86M
                int dq_sat;
648
649
2.86M
                if (rc_tok >= (15 << 11)) {
650
267k
                    tok = read_golomb(&ts->msac) + 15;
651
267k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
267k
                    tok &= 0xfffff;
656
267k
                    dq = (dq * tok) & 0xffffff;
657
2.59M
                } else {
658
2.59M
                    tok = rc_tok >> 11;
659
2.59M
                    dq *= tok;
660
2.59M
                    assert(dq <= 0xffffff);
661
2.59M
                }
662
2.86M
                cul_level += tok;
663
2.86M
                dq >>= dq_shift;
664
2.86M
                dq_sat = umin(dq, cf_max + sign);
665
2.86M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
2.86M
                rc = rc_tok & 0x3ff;
668
2.86M
            } while (rc);
669
400k
        }
670
542k
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
542k
        if (dc_tok == 15) {
673
11.8k
            dc_tok = read_golomb(&ts->msac) + 15;
674
11.8k
            if (dbg)
675
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
676
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
677
678
11.8k
            dc_tok &= 0xfffff;
679
11.8k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
11.8k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
530k
        } else {
682
530k
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
530k
            assert(dc_dq <= cf_max);
684
530k
        }
685
542k
        cul_level = dc_tok;
686
542k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
658k
        if (rc) ac_noqm: {
689
658k
            const unsigned ac_dq = dq_tbl[1];
690
2.95M
            do {
691
2.95M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
2.95M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
2.95M
                const unsigned rc_tok = cf[rc];
695
2.95M
                unsigned tok;
696
2.95M
                int dq;
697
698
                // residual
699
2.95M
                if (rc_tok >= (15 << 11)) {
700
38.7k
                    tok = read_golomb(&ts->msac) + 15;
701
38.7k
                    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
38.7k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
38.7k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
38.7k
                    dq = umin(dq, cf_max + sign);
711
2.91M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
2.91M
                    tok = rc_tok >> 11;
714
2.91M
                    dq = ((ac_dq * tok) >> dq_shift);
715
2.91M
                    assert(dq <= cf_max);
716
2.91M
                }
717
2.95M
                cul_level += tok;
718
2.95M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
2.95M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
2.95M
            } while (rc);
722
658k
        }
723
542k
    }
724
725
    // context
726
1.00M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
1.00M
    return eob;
729
835k
}
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
601k
{
737
601k
    const Dav1dFrameContext *const f = t->f;
738
601k
    Dav1dTileState *const ts = t->ts;
739
601k
    const Dav1dDSPContext *const dsp = f->dsp;
740
601k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
601k
    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
601k
    if (depth < 2 && tx_split[depth] &&
746
30.6k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
24.7k
    {
748
24.7k
        const enum RectTxfmSize sub = t_dim->sub;
749
24.7k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
24.7k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
24.7k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
24.7k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
24.7k
        t->bx += txsw;
755
24.7k
        if (txw >= txh && t->bx < f->bw)
756
14.0k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
14.0k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
24.7k
        t->bx -= txsw;
759
24.7k
        t->by += txsh;
760
24.7k
        if (txh >= txw && t->by < f->bh) {
761
20.0k
            if (dst)
762
9.08k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
20.0k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
20.0k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
20.0k
            t->bx += txsw;
766
20.0k
            if (txw >= txh && t->bx < f->bw)
767
9.87k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
9.87k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
20.0k
            t->bx -= txsw;
770
20.0k
        }
771
24.7k
        t->by -= txsh;
772
576k
    } else {
773
576k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
576k
        enum TxfmType txtp;
775
576k
        uint8_t cf_ctx;
776
576k
        int eob;
777
576k
        coef *cf;
778
779
576k
        if (t->frame_thread.pass) {
780
576k
            const int p = t->frame_thread.pass & 1;
781
576k
            assert(ts->frame_thread[p].cf);
782
576k
            cf = ts->frame_thread[p].cf;
783
576k
            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
576k
        if (t->frame_thread.pass != 2) {
788
369k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
369k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
369k
            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
369k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
369k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
369k
#define set_ctx(rep_macro) \
796
1.29M
            for (int y = 0; y < txh; y++) { \
797
923k
                rep_macro(txtp_map, 0, txtp); \
798
923k
                txtp_map += 32; \
799
923k
            }
800
369k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
369k
            case_set_upto16(t_dim->lw);
802
369k
#undef set_ctx
803
369k
            if (t->frame_thread.pass == 1)
804
369k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
369k
        } else {
806
207k
            const int cbi = *ts->frame_thread[0].cbi++;
807
207k
            eob  = cbi >> 5;
808
207k
            txtp = cbi & 0x1f;
809
207k
        }
810
576k
        if (!(t->frame_thread.pass & 1)) {
811
207k
            assert(dst);
812
207k
            if (eob >= 0) {
813
122k
                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
122k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
122k
                                              HIGHBD_CALL_SUFFIX);
817
122k
                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
122k
            }
820
207k
        }
821
576k
    }
822
601k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
1.00M
{
827
1.00M
    const Dav1dFrameContext *const f = t->f;
828
1.00M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.00M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.00M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.00M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.00M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.00M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.00M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.00M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
908k
                           (bw4 > ss_hor || t->bx & 1) &&
837
848k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.00M
    if (b->skip) {
840
638k
        BlockContext *const a = t->a;
841
638k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
638k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
638k
        if (has_chroma) {
844
480k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
480k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
480k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
480k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
480k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
480k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
480k
        }
851
638k
        return;
852
638k
    }
853
854
368k
    Dav1dTileState *const ts = t->ts;
855
368k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
368k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
368k
    assert(t->frame_thread.pass == 1);
858
368k
    assert(!b->skip);
859
368k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
368k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
368k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
749k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
381k
        const int sub_h4 = imin(h4, 16 + init_y);
865
775k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
394k
            const int sub_w4 = imin(w4, init_x + 16);
867
394k
            int y_off = !!init_y, y, x;
868
863k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
469k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
469k
            {
871
469k
                int x_off = !!init_x;
872
1.24M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
779k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
779k
                {
875
779k
                    if (!b->intra) {
876
344k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
344k
                                       x_off, y_off, NULL);
878
434k
                    } else {
879
434k
                        uint8_t cf_ctx = 0x40;
880
434k
                        enum TxfmType txtp;
881
434k
                        const int eob =
882
434k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
434k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
434k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
434k
                        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
434k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
434k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
434k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
434k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
434k
                    }
893
779k
                }
894
469k
                t->bx -= x;
895
469k
            }
896
394k
            t->by -= y;
897
898
394k
            if (!has_chroma) continue;
899
900
329k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
329k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
988k
            for (int pl = 0; pl < 2; pl++) {
903
1.41M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
760k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
760k
                {
906
1.89M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.13M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.13M
                    {
909
1.13M
                        uint8_t cf_ctx = 0x40;
910
1.13M
                        enum TxfmType txtp;
911
1.13M
                        if (!b->intra)
912
645k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
645k
                                                        bx4 + (x << ss_hor)];
914
1.13M
                        const int eob =
915
1.13M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.13M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.13M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.13M
                                         &txtp, &cf_ctx);
919
1.13M
                        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.13M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.13M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.13M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.13M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.13M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.13M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.13M
                    }
930
760k
                    t->bx -= x << ss_hor;
931
760k
                }
932
659k
                t->by -= y << ss_ver;
933
659k
            }
934
329k
        }
935
381k
    }
936
368k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
533k
{
827
533k
    const Dav1dFrameContext *const f = t->f;
828
533k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
533k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
533k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
533k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
533k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
533k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
533k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
533k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
490k
                           (bw4 > ss_hor || t->bx & 1) &&
837
455k
                           (bh4 > ss_ver || t->by & 1);
838
839
533k
    if (b->skip) {
840
374k
        BlockContext *const a = t->a;
841
374k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
374k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
374k
        if (has_chroma) {
844
292k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
292k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
292k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
292k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
292k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
292k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
292k
        }
851
374k
        return;
852
374k
    }
853
854
158k
    Dav1dTileState *const ts = t->ts;
855
158k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
158k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
158k
    assert(t->frame_thread.pass == 1);
858
158k
    assert(!b->skip);
859
158k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
158k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
158k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
322k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
163k
        const int sub_h4 = imin(h4, 16 + init_y);
865
331k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
167k
            const int sub_w4 = imin(w4, init_x + 16);
867
167k
            int y_off = !!init_y, y, x;
868
361k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
193k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
193k
            {
871
193k
                int x_off = !!init_x;
872
493k
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
300k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
300k
                {
875
300k
                    if (!b->intra) {
876
98.2k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
98.2k
                                       x_off, y_off, NULL);
878
201k
                    } else {
879
201k
                        uint8_t cf_ctx = 0x40;
880
201k
                        enum TxfmType txtp;
881
201k
                        const int eob =
882
201k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
201k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
201k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
201k
                        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
201k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
201k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
201k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
201k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
201k
                    }
893
300k
                }
894
193k
                t->bx -= x;
895
193k
            }
896
167k
            t->by -= y;
897
898
167k
            if (!has_chroma) continue;
899
900
134k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
134k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
403k
            for (int pl = 0; pl < 2; pl++) {
903
563k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
293k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
293k
                {
906
659k
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
365k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
365k
                    {
909
365k
                        uint8_t cf_ctx = 0x40;
910
365k
                        enum TxfmType txtp;
911
365k
                        if (!b->intra)
912
183k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
183k
                                                        bx4 + (x << ss_hor)];
914
365k
                        const int eob =
915
365k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
365k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
365k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
365k
                                         &txtp, &cf_ctx);
919
365k
                        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
365k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
365k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
365k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
365k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
365k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
365k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
365k
                    }
930
293k
                    t->bx -= x << ss_hor;
931
293k
                }
932
269k
                t->by -= y << ss_ver;
933
269k
            }
934
134k
        }
935
163k
    }
936
158k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
473k
{
827
473k
    const Dav1dFrameContext *const f = t->f;
828
473k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
473k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
473k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
473k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
473k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
473k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
473k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
473k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
417k
                           (bw4 > ss_hor || t->bx & 1) &&
837
392k
                           (bh4 > ss_ver || t->by & 1);
838
839
473k
    if (b->skip) {
840
264k
        BlockContext *const a = t->a;
841
264k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
264k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
264k
        if (has_chroma) {
844
187k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
187k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
187k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
187k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
187k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
187k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
187k
        }
851
264k
        return;
852
264k
    }
853
854
209k
    Dav1dTileState *const ts = t->ts;
855
209k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
209k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
209k
    assert(t->frame_thread.pass == 1);
858
209k
    assert(!b->skip);
859
209k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
209k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
209k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
426k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
217k
        const int sub_h4 = imin(h4, 16 + init_y);
865
443k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
226k
            const int sub_w4 = imin(w4, init_x + 16);
867
226k
            int y_off = !!init_y, y, x;
868
502k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
275k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
275k
            {
871
275k
                int x_off = !!init_x;
872
755k
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
479k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
479k
                {
875
479k
                    if (!b->intra) {
876
246k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
246k
                                       x_off, y_off, NULL);
878
246k
                    } else {
879
232k
                        uint8_t cf_ctx = 0x40;
880
232k
                        enum TxfmType txtp;
881
232k
                        const int eob =
882
232k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
232k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
232k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
232k
                        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
232k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
232k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
232k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
232k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
232k
                    }
893
479k
                }
894
275k
                t->bx -= x;
895
275k
            }
896
226k
            t->by -= y;
897
898
226k
            if (!has_chroma) continue;
899
900
194k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
194k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
584k
            for (int pl = 0; pl < 2; pl++) {
903
856k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
466k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
466k
                {
906
1.23M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
768k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
768k
                    {
909
768k
                        uint8_t cf_ctx = 0x40;
910
768k
                        enum TxfmType txtp;
911
768k
                        if (!b->intra)
912
462k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
462k
                                                        bx4 + (x << ss_hor)];
914
768k
                        const int eob =
915
768k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
768k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
768k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
768k
                                         &txtp, &cf_ctx);
919
768k
                        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
768k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
768k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
768k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
768k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
768k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
768k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
768k
                    }
930
466k
                    t->bx -= x << ss_hor;
931
466k
                }
932
389k
                t->by -= y << ss_ver;
933
389k
            }
934
194k
        }
935
217k
    }
936
209k
}
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
518k
{
945
518k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
518k
    const Dav1dFrameContext *const f = t->f;
947
518k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
518k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
518k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
518k
    const int mvx = mv.x, mvy = mv.y;
951
518k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
518k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
518k
    const pixel *ref;
954
955
518k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
320k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
320k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
320k
        int w, h;
959
960
320k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
267k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
267k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
267k
        } else {
964
52.7k
            w = f->bw * 4 >> ss_hor;
965
52.7k
            h = f->bh * 4 >> ss_ver;
966
52.7k
        }
967
320k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
224k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
111k
            dy + bh4 * v_mul + !!my * 4 > h)
970
235k
        {
971
235k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
235k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
235k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
235k
                                emu_edge_buf, 192 * sizeof(pixel),
975
235k
                                refp->p.data[pl], ref_stride);
976
235k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
235k
            ref_stride = 192 * sizeof(pixel);
978
235k
        } else {
979
84.9k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
84.9k
        }
981
982
320k
        if (dst8 != NULL) {
983
253k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
253k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
253k
                                     HIGHBD_CALL_SUFFIX);
986
253k
        } else {
987
67.2k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
67.2k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
67.2k
                                      HIGHBD_CALL_SUFFIX);
990
67.2k
        }
991
320k
    } else {
992
197k
        assert(refp != &f->sr_cur);
993
994
197k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
197k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
395k
#define scale_mv(res, val, scale) do { \
997
395k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
395k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
395k
        } while (0)
1000
197k
        int pos_y, pos_x;
1001
197k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
197k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
197k
#undef scale_mv
1004
197k
        const int left = pos_x >> 10;
1005
197k
        const int top = pos_y >> 10;
1006
197k
        const int right =
1007
197k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
197k
        const int bottom =
1009
197k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
197k
        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
197k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
197k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
197k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
96.4k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
96.4k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
96.4k
                                w, h, left - 3, top - 3,
1023
96.4k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
96.4k
                                refp->p.data[pl], ref_stride);
1025
96.4k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
96.4k
            ref_stride = 320 * sizeof(pixel);
1027
96.4k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
101k
        } else {
1029
101k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
101k
        }
1031
1032
197k
        if (dst8 != NULL) {
1033
152k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
152k
                                            bw4 * h_mul, bh4 * v_mul,
1035
152k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
152k
                                            f->svc[refidx][0].step,
1037
152k
                                            f->svc[refidx][1].step
1038
152k
                                            HIGHBD_CALL_SUFFIX);
1039
152k
        } else {
1040
45.2k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
45.2k
                                             bw4 * h_mul, bh4 * v_mul,
1042
45.2k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
45.2k
                                             f->svc[refidx][0].step,
1044
45.2k
                                             f->svc[refidx][1].step
1045
45.2k
                                             HIGHBD_CALL_SUFFIX);
1046
45.2k
        }
1047
197k
    }
1048
1049
518k
    return 0;
1050
518k
}
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
31.7k
{
1057
31.7k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
31.7k
    const Dav1dFrameContext *const f = t->f;
1059
31.7k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
31.7k
    pixel *const lap = bitfn(t->scratch.lap);
1061
31.7k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
31.7k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
31.7k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
31.7k
    int res;
1065
1066
31.7k
    if (t->by > t->ts->tiling.row_start &&
1067
28.0k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
26.9k
    {
1069
56.7k
        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
29.8k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
29.8k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
29.8k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
29.8k
            if (a_r->ref.ref[0] > 0) {
1076
29.2k
                const int ow4 = imin(step4, b_dim[0]);
1077
29.2k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
29.2k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
29.2k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
29.2k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
29.2k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
29.2k
                if (res) return res;
1083
29.2k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
29.2k
                                   h_mul * ow4, v_mul * oh4);
1085
29.2k
                i++;
1086
29.2k
            }
1087
29.8k
            x += step4;
1088
29.8k
        }
1089
26.9k
    }
1090
1091
31.7k
    if (t->bx > t->ts->tiling.col_start)
1092
56.3k
        for (int i = 0, y = 0; y < h4 && i < imin(b_dim[3], 4); ) {
1093
            // only odd blocks are considered for overlap handling, hence +1
1094
29.4k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
29.4k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
29.4k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
29.4k
            if (l_r->ref.ref[0] > 0) {
1099
28.6k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
28.6k
                const int oh4 = imin(step4, b_dim[1]);
1101
28.6k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
28.6k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
28.6k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
28.6k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
28.6k
                if (res) return res;
1106
28.6k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
28.6k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
28.6k
                i++;
1109
28.6k
            }
1110
29.4k
            y += step4;
1111
29.4k
        }
1112
31.7k
    return 0;
1113
31.7k
}
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
16.3k
{
1121
16.3k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
16.3k
    const Dav1dFrameContext *const f = t->f;
1123
16.3k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
16.3k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
16.3k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
16.3k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
16.3k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
16.3k
    const int32_t *const mat = wmp->matrix;
1129
16.3k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
16.3k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
66.1k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
49.8k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
49.8k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
49.8k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
271k
        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
221k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
221k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
221k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
221k
            const int dx = (int) (mvx >> 16) - 4;
1144
221k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
221k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
221k
            const int dy = (int) (mvy >> 16) - 4;
1147
221k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
221k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
221k
            const pixel *ref_ptr;
1151
221k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
221k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
192k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
192k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
192k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
192k
                                    refp->p.data[pl], ref_stride);
1158
192k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
192k
                ref_stride = 32 * sizeof(pixel);
1160
192k
            } else {
1161
29.4k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
29.4k
            }
1163
221k
            if (dst16 != NULL)
1164
10.9k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
10.9k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
210k
            else
1167
210k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
210k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
221k
        }
1170
49.8k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
6.82k
        else      dst16 += 8 * dstride;
1172
49.8k
    }
1173
16.3k
    return 0;
1174
16.3k
}
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
600k
{
1180
600k
    Dav1dTileState *const ts = t->ts;
1181
600k
    const Dav1dFrameContext *const f = t->f;
1182
600k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
600k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
600k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
600k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
600k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
600k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
600k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
600k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
600k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
600k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
577k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
535k
                           (bh4 > ss_ver || t->by & 1);
1194
600k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
600k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
600k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
600k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
600k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.21M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
608k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
608k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.23M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
622k
            if (b->pal_sz[0]) {
1208
5.68k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
5.68k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
5.68k
                const uint8_t *pal_idx;
1211
5.68k
                if (t->frame_thread.pass) {
1212
5.68k
                    const int p = t->frame_thread.pass & 1;
1213
5.68k
                    assert(ts->frame_thread[p].pal_idx);
1214
5.68k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
5.68k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
5.68k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
5.68k
                const pixel *const pal = t->frame_thread.pass ?
1220
5.68k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
5.68k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
5.68k
                    bytefn(t->scratch.pal)[0];
1223
5.68k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
5.68k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
5.68k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
5.68k
            }
1229
1230
622k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
622k
                                     sm_flag(&t->l, by4) |
1232
622k
                                     intra_edge_filter_flag);
1233
622k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
608k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
622k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
608k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
622k
            int y, x;
1238
622k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.37M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
750k
                 y += t_dim->h, t->by += t_dim->h)
1241
747k
            {
1242
747k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
747k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
747k
                                    t->bx + init_x);
1245
2.09M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.35M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.34M
                {
1248
1.34M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.34M
                    int angle = b->y_angle;
1251
1.34M
                    const enum EdgeFlags edge_flags =
1252
1.34M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
989k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.34M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
963k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.34M
                    const pixel *top_sb_edge = NULL;
1257
1.34M
                    if (!(t->by & (f->sb_step - 1))) {
1258
201k
                        top_sb_edge = f->ipred_edge[0];
1259
201k
                        const int sby = t->by >> f->sb_shift;
1260
201k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
201k
                    }
1262
1.34M
                    const enum IntraPredMode m =
1263
1.34M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.34M
                                                          t->bx > ts->tiling.col_start,
1265
1.34M
                                                          t->by,
1266
1.34M
                                                          t->by > ts->tiling.row_start,
1267
1.34M
                                                          ts->tiling.col_end,
1268
1.34M
                                                          ts->tiling.row_end,
1269
1.34M
                                                          edge_flags, dst,
1270
1.34M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.34M
                                                          b->y_mode, &angle,
1272
1.34M
                                                          t_dim->w, t_dim->h,
1273
1.34M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.34M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.34M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.34M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.34M
                                             angle | intra_flags,
1278
1.34M
                                             4 * f->bw - 4 * t->bx,
1279
1.34M
                                             4 * f->bh - 4 * t->by
1280
1.34M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.34M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.35M
                skip_y_pred: {}
1293
1.35M
                    if (!b->skip) {
1294
312k
                        coef *cf;
1295
312k
                        int eob;
1296
312k
                        enum TxfmType txtp;
1297
312k
                        if (t->frame_thread.pass) {
1298
312k
                            const int p = t->frame_thread.pass & 1;
1299
312k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
312k
                            cf = ts->frame_thread[p].cf;
1301
312k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
312k
                            eob  = cbi >> 5;
1303
312k
                            txtp = cbi & 0x1f;
1304
312k
                        } 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
312k
                        if (eob >= 0) {
1317
245k
                            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
245k
                            dsp->itx.itxfm_add[b->tx]
1321
245k
                                              [txtp](dst,
1322
245k
                                                     f->cur.stride[0],
1323
245k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
245k
                            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
245k
                        }
1328
1.03M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.35M
                    dst += 4 * t_dim->w;
1333
1.35M
                }
1334
750k
                t->bx -= x;
1335
750k
            }
1336
625k
            t->by -= y;
1337
1338
625k
            if (!has_chroma) continue;
1339
1340
512k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
512k
            if (b->uv_mode == CFL_PRED) {
1343
94.9k
                assert(!init_x && !init_y);
1344
1345
94.9k
                int16_t *const ac = t->scratch.ac;
1346
94.9k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
94.9k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
94.9k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
94.9k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
94.9k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
94.9k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
94.9k
                const int furthest_r =
1354
94.9k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
94.9k
                const int furthest_b =
1356
94.9k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
94.9k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
94.9k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
94.9k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
94.9k
                                                         cbw4 * 4, cbh4 * 4);
1361
284k
                for (int pl = 0; pl < 2; pl++) {
1362
189k
                    if (!b->cfl_alpha[pl]) continue;
1363
150k
                    int angle = 0;
1364
150k
                    const pixel *top_sb_edge = NULL;
1365
150k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
28.6k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
28.6k
                        const int sby = t->by >> f->sb_shift;
1368
28.6k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
28.6k
                    }
1370
150k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
150k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
150k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
150k
                    const enum IntraPredMode m =
1374
150k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
150k
                                                          ypos, ypos > ystart,
1376
150k
                                                          ts->tiling.col_end >> ss_hor,
1377
150k
                                                          ts->tiling.row_end >> ss_ver,
1378
150k
                                                          0, uv_dst[pl], stride,
1379
150k
                                                          top_sb_edge, DC_PRED, &angle,
1380
150k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
150k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
150k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
150k
                                           uv_t_dim->w * 4,
1384
150k
                                           uv_t_dim->h * 4,
1385
150k
                                           ac, b->cfl_alpha[pl]
1386
150k
                                           HIGHBD_CALL_SUFFIX);
1387
150k
                }
1388
94.9k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
418k
            } else if (b->pal_sz[1]) {
1394
3.12k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
3.12k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
3.12k
                const pixel (*pal)[8];
1397
3.12k
                const uint8_t *pal_idx;
1398
3.12k
                if (t->frame_thread.pass) {
1399
3.12k
                    const int p = t->frame_thread.pass & 1;
1400
3.12k
                    assert(ts->frame_thread[p].pal_idx);
1401
3.12k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
3.12k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
3.12k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
3.12k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
3.12k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
3.12k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
3.12k
                                       f->cur.stride[1], pal[1],
1412
3.12k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
3.12k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
3.12k
                                       f->cur.stride[1], pal[2],
1415
3.12k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
3.12k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
3.12k
            }
1425
1426
512k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
512k
                                 sm_uv_flag(&t->l, cby4);
1428
512k
            const int uv_sb_has_tr =
1429
512k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
500k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
512k
            const int uv_sb_has_bl =
1432
512k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
500k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
512k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.53M
            for (int pl = 0; pl < 2; pl++) {
1436
2.08M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.06M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.06M
                {
1439
1.06M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.06M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.06M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.35M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.28M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.28M
                    {
1445
1.28M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.13M
                            b->pal_sz[1])
1447
156k
                        {
1448
156k
                            goto skip_uv_pred;
1449
156k
                        }
1450
1451
1.12M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
1.12M
                        const enum EdgeFlags edge_flags =
1456
1.12M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
532k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
775k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.12M
                            ((x > (init_x >> ss_hor) ||
1460
911k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
740k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.12M
                        const pixel *top_sb_edge = NULL;
1463
1.12M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
271k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
271k
                            const int sby = t->by >> f->sb_shift;
1466
271k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
271k
                        }
1468
1.12M
                        const enum IntraPredMode uv_mode =
1469
1.12M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.12M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.12M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.12M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.12M
                        const enum IntraPredMode m =
1474
1.12M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.12M
                                                              ypos, ypos > ystart,
1476
1.12M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.12M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.12M
                                                              edge_flags, dst, stride,
1479
1.12M
                                                              top_sb_edge, uv_mode,
1480
1.12M
                                                              &angle, uv_t_dim->w,
1481
1.12M
                                                              uv_t_dim->h,
1482
1.12M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.12M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.12M
                        angle |= intra_edge_filter_flag;
1485
1.12M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.12M
                                                 uv_t_dim->w * 4,
1487
1.12M
                                                 uv_t_dim->h * 4,
1488
1.12M
                                                 angle | sm_uv_fl,
1489
1.12M
                                                 (4 * f->bw + ss_hor -
1490
1.12M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.12M
                                                 (4 * f->bh + ss_ver -
1492
1.12M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.12M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.12M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
1.28M
                    skip_uv_pred: {}
1505
1.28M
                        if (!b->skip) {
1506
372k
                            enum TxfmType txtp;
1507
372k
                            int eob;
1508
372k
                            coef *cf;
1509
372k
                            if (t->frame_thread.pass) {
1510
372k
                                const int p = t->frame_thread.pass & 1;
1511
372k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
372k
                                cf = ts->frame_thread[p].cf;
1513
372k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
372k
                                eob  = cbi >> 5;
1515
372k
                                txtp = cbi & 0x1f;
1516
372k
                            } 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
372k
                            if (eob >= 0) {
1533
142k
                                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
142k
                                dsp->itx.itxfm_add[b->uvtx]
1537
142k
                                                  [txtp](dst, stride,
1538
142k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
142k
                                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
142k
                            }
1543
909k
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
1.28M
                        dst += uv_t_dim->w * 4;
1548
1.28M
                    }
1549
1.06M
                    t->bx -= x << ss_hor;
1550
1.06M
                }
1551
1.01M
                t->by -= y << ss_ver;
1552
1.01M
            }
1553
512k
        }
1554
608k
    }
1555
600k
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
335k
{
1180
335k
    Dav1dTileState *const ts = t->ts;
1181
335k
    const Dav1dFrameContext *const f = t->f;
1182
335k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
335k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
335k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
335k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
335k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
335k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
335k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
335k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
335k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
335k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
318k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
294k
                           (bh4 > ss_ver || t->by & 1);
1194
335k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
335k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
335k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
335k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
335k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
676k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
338k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
338k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
683k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
342k
            if (b->pal_sz[0]) {
1208
3.05k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
3.05k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
3.05k
                const uint8_t *pal_idx;
1211
3.05k
                if (t->frame_thread.pass) {
1212
3.05k
                    const int p = t->frame_thread.pass & 1;
1213
3.05k
                    assert(ts->frame_thread[p].pal_idx);
1214
3.05k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
3.05k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
3.05k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
3.05k
                const pixel *const pal = t->frame_thread.pass ?
1220
3.05k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
3.05k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
3.05k
                    bytefn(t->scratch.pal)[0];
1223
3.05k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
3.05k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
3.05k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
3.05k
            }
1229
1230
342k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
342k
                                     sm_flag(&t->l, by4) |
1232
342k
                                     intra_edge_filter_flag);
1233
342k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
338k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
342k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
338k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
342k
            int y, x;
1238
342k
            const int sub_w4 = imin(w4, init_x + 16);
1239
749k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
407k
                 y += t_dim->h, t->by += t_dim->h)
1241
404k
            {
1242
404k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
404k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
404k
                                    t->bx + init_x);
1245
1.11M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
713k
                     x += t_dim->w, t->bx += t_dim->w)
1247
711k
                {
1248
711k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
708k
                    int angle = b->y_angle;
1251
708k
                    const enum EdgeFlags edge_flags =
1252
708k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
526k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
708k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
511k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
708k
                    const pixel *top_sb_edge = NULL;
1257
708k
                    if (!(t->by & (f->sb_step - 1))) {
1258
120k
                        top_sb_edge = f->ipred_edge[0];
1259
120k
                        const int sby = t->by >> f->sb_shift;
1260
120k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
120k
                    }
1262
708k
                    const enum IntraPredMode m =
1263
708k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
708k
                                                          t->bx > ts->tiling.col_start,
1265
708k
                                                          t->by,
1266
708k
                                                          t->by > ts->tiling.row_start,
1267
708k
                                                          ts->tiling.col_end,
1268
708k
                                                          ts->tiling.row_end,
1269
708k
                                                          edge_flags, dst,
1270
708k
                                                          f->cur.stride[0], top_sb_edge,
1271
708k
                                                          b->y_mode, &angle,
1272
708k
                                                          t_dim->w, t_dim->h,
1273
708k
                                                          f->seq_hdr->intra_edge_filter,
1274
708k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
708k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
708k
                                             t_dim->w * 4, t_dim->h * 4,
1277
708k
                                             angle | intra_flags,
1278
708k
                                             4 * f->bw - 4 * t->bx,
1279
708k
                                             4 * f->bh - 4 * t->by
1280
708k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
708k
                    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
713k
                skip_y_pred: {}
1293
713k
                    if (!b->skip) {
1294
141k
                        coef *cf;
1295
141k
                        int eob;
1296
141k
                        enum TxfmType txtp;
1297
141k
                        if (t->frame_thread.pass) {
1298
141k
                            const int p = t->frame_thread.pass & 1;
1299
141k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
141k
                            cf = ts->frame_thread[p].cf;
1301
141k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
141k
                            eob  = cbi >> 5;
1303
141k
                            txtp = cbi & 0x1f;
1304
141k
                        } 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
141k
                        if (eob >= 0) {
1317
113k
                            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
113k
                            dsp->itx.itxfm_add[b->tx]
1321
113k
                                              [txtp](dst,
1322
113k
                                                     f->cur.stride[0],
1323
113k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
113k
                            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
113k
                        }
1328
572k
                    } 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
713k
                    dst += 4 * t_dim->w;
1333
713k
                }
1334
407k
                t->bx -= x;
1335
407k
            }
1336
345k
            t->by -= y;
1337
1338
345k
            if (!has_chroma) continue;
1339
1340
276k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
276k
            if (b->uv_mode == CFL_PRED) {
1343
52.6k
                assert(!init_x && !init_y);
1344
1345
52.6k
                int16_t *const ac = t->scratch.ac;
1346
52.6k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
52.6k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
52.6k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
52.6k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
52.6k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
52.6k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
52.6k
                const int furthest_r =
1354
52.6k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
52.6k
                const int furthest_b =
1356
52.6k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
52.6k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
52.6k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
52.6k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
52.6k
                                                         cbw4 * 4, cbh4 * 4);
1361
157k
                for (int pl = 0; pl < 2; pl++) {
1362
105k
                    if (!b->cfl_alpha[pl]) continue;
1363
84.1k
                    int angle = 0;
1364
84.1k
                    const pixel *top_sb_edge = NULL;
1365
84.1k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
17.2k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
17.2k
                        const int sby = t->by >> f->sb_shift;
1368
17.2k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
17.2k
                    }
1370
84.1k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
84.1k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
84.1k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
84.1k
                    const enum IntraPredMode m =
1374
84.1k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
84.1k
                                                          ypos, ypos > ystart,
1376
84.1k
                                                          ts->tiling.col_end >> ss_hor,
1377
84.1k
                                                          ts->tiling.row_end >> ss_ver,
1378
84.1k
                                                          0, uv_dst[pl], stride,
1379
84.1k
                                                          top_sb_edge, DC_PRED, &angle,
1380
84.1k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
84.1k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
84.1k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
84.1k
                                           uv_t_dim->w * 4,
1384
84.1k
                                           uv_t_dim->h * 4,
1385
84.1k
                                           ac, b->cfl_alpha[pl]
1386
84.1k
                                           HIGHBD_CALL_SUFFIX);
1387
84.1k
                }
1388
52.6k
                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
223k
            } else if (b->pal_sz[1]) {
1394
1.43k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.43k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.43k
                const pixel (*pal)[8];
1397
1.43k
                const uint8_t *pal_idx;
1398
1.43k
                if (t->frame_thread.pass) {
1399
1.43k
                    const int p = t->frame_thread.pass & 1;
1400
1.43k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.43k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.43k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.43k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.43k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.43k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.43k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.43k
                                       f->cur.stride[1], pal[1],
1412
1.43k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.43k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.43k
                                       f->cur.stride[1], pal[2],
1415
1.43k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.43k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.43k
            }
1425
1426
276k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
276k
                                 sm_uv_flag(&t->l, cby4);
1428
276k
            const int uv_sb_has_tr =
1429
276k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
271k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
276k
            const int uv_sb_has_bl =
1432
276k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
271k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
276k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
823k
            for (int pl = 0; pl < 2; pl++) {
1436
1.11M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
569k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
569k
                {
1439
569k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
569k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
569k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.24M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
679k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
679k
                    {
1445
679k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
594k
                            b->pal_sz[1])
1447
87.0k
                        {
1448
87.0k
                            goto skip_uv_pred;
1449
87.0k
                        }
1450
1451
592k
                        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
592k
                        const enum EdgeFlags edge_flags =
1456
592k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
270k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
418k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
592k
                            ((x > (init_x >> ss_hor) ||
1460
482k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
397k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
592k
                        const pixel *top_sb_edge = NULL;
1463
592k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
161k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
161k
                            const int sby = t->by >> f->sb_shift;
1466
161k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
161k
                        }
1468
592k
                        const enum IntraPredMode uv_mode =
1469
592k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
592k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
592k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
592k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
592k
                        const enum IntraPredMode m =
1474
592k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
592k
                                                              ypos, ypos > ystart,
1476
592k
                                                              ts->tiling.col_end >> ss_hor,
1477
592k
                                                              ts->tiling.row_end >> ss_ver,
1478
592k
                                                              edge_flags, dst, stride,
1479
592k
                                                              top_sb_edge, uv_mode,
1480
592k
                                                              &angle, uv_t_dim->w,
1481
592k
                                                              uv_t_dim->h,
1482
592k
                                                              f->seq_hdr->intra_edge_filter,
1483
592k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
592k
                        angle |= intra_edge_filter_flag;
1485
592k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
592k
                                                 uv_t_dim->w * 4,
1487
592k
                                                 uv_t_dim->h * 4,
1488
592k
                                                 angle | sm_uv_fl,
1489
592k
                                                 (4 * f->bw + ss_hor -
1490
592k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
592k
                                                 (4 * f->bh + ss_ver -
1492
592k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
592k
                                                 HIGHBD_CALL_SUFFIX);
1494
592k
                        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
679k
                    skip_uv_pred: {}
1505
679k
                        if (!b->skip) {
1506
134k
                            enum TxfmType txtp;
1507
134k
                            int eob;
1508
134k
                            coef *cf;
1509
134k
                            if (t->frame_thread.pass) {
1510
134k
                                const int p = t->frame_thread.pass & 1;
1511
134k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
134k
                                cf = ts->frame_thread[p].cf;
1513
134k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
134k
                                eob  = cbi >> 5;
1515
134k
                                txtp = cbi & 0x1f;
1516
134k
                            } 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
134k
                            if (eob >= 0) {
1533
69.4k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
69.4k
                                dsp->itx.itxfm_add[b->uvtx]
1537
69.4k
                                                  [txtp](dst, stride,
1538
69.4k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
69.4k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
69.4k
                            }
1543
544k
                        } 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
679k
                        dst += uv_t_dim->w * 4;
1548
679k
                    }
1549
569k
                    t->bx -= x << ss_hor;
1550
569k
                }
1551
547k
                t->by -= y << ss_ver;
1552
547k
            }
1553
276k
        }
1554
338k
    }
1555
335k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
265k
{
1180
265k
    Dav1dTileState *const ts = t->ts;
1181
265k
    const Dav1dFrameContext *const f = t->f;
1182
265k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
265k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
265k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
265k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
265k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
265k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
265k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
265k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
265k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
265k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
259k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
241k
                           (bh4 > ss_ver || t->by & 1);
1194
265k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
265k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
265k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
265k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
265k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
536k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
270k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
270k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
550k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
279k
            if (b->pal_sz[0]) {
1208
2.63k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
2.63k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
2.63k
                const uint8_t *pal_idx;
1211
2.63k
                if (t->frame_thread.pass) {
1212
2.63k
                    const int p = t->frame_thread.pass & 1;
1213
2.63k
                    assert(ts->frame_thread[p].pal_idx);
1214
2.63k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
2.63k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
2.63k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
2.63k
                const pixel *const pal = t->frame_thread.pass ?
1220
2.63k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
2.63k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
2.63k
                    bytefn(t->scratch.pal)[0];
1223
2.63k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
2.63k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
2.63k
                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
2.63k
            }
1229
1230
279k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
279k
                                     sm_flag(&t->l, by4) |
1232
279k
                                     intra_edge_filter_flag);
1233
279k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
270k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
279k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
270k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
279k
            int y, x;
1238
279k
            const int sub_w4 = imin(w4, init_x + 16);
1239
622k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
343k
                 y += t_dim->h, t->by += t_dim->h)
1241
342k
            {
1242
342k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
342k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
342k
                                    t->bx + init_x);
1245
980k
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
638k
                     x += t_dim->w, t->bx += t_dim->w)
1247
637k
                {
1248
637k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
634k
                    int angle = b->y_angle;
1251
634k
                    const enum EdgeFlags edge_flags =
1252
634k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
462k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
634k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
452k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
634k
                    const pixel *top_sb_edge = NULL;
1257
634k
                    if (!(t->by & (f->sb_step - 1))) {
1258
81.3k
                        top_sb_edge = f->ipred_edge[0];
1259
81.3k
                        const int sby = t->by >> f->sb_shift;
1260
81.3k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
81.3k
                    }
1262
634k
                    const enum IntraPredMode m =
1263
634k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
634k
                                                          t->bx > ts->tiling.col_start,
1265
634k
                                                          t->by,
1266
634k
                                                          t->by > ts->tiling.row_start,
1267
634k
                                                          ts->tiling.col_end,
1268
634k
                                                          ts->tiling.row_end,
1269
634k
                                                          edge_flags, dst,
1270
634k
                                                          f->cur.stride[0], top_sb_edge,
1271
634k
                                                          b->y_mode, &angle,
1272
634k
                                                          t_dim->w, t_dim->h,
1273
634k
                                                          f->seq_hdr->intra_edge_filter,
1274
634k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
634k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
634k
                                             t_dim->w * 4, t_dim->h * 4,
1277
634k
                                             angle | intra_flags,
1278
634k
                                             4 * f->bw - 4 * t->bx,
1279
634k
                                             4 * f->bh - 4 * t->by
1280
634k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
634k
                    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
638k
                skip_y_pred: {}
1293
638k
                    if (!b->skip) {
1294
171k
                        coef *cf;
1295
171k
                        int eob;
1296
171k
                        enum TxfmType txtp;
1297
171k
                        if (t->frame_thread.pass) {
1298
171k
                            const int p = t->frame_thread.pass & 1;
1299
171k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
171k
                            cf = ts->frame_thread[p].cf;
1301
171k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
171k
                            eob  = cbi >> 5;
1303
171k
                            txtp = cbi & 0x1f;
1304
171k
                        } 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
171k
                        if (eob >= 0) {
1317
132k
                            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
132k
                            dsp->itx.itxfm_add[b->tx]
1321
132k
                                              [txtp](dst,
1322
132k
                                                     f->cur.stride[0],
1323
132k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
132k
                            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
132k
                        }
1328
466k
                    } 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
638k
                    dst += 4 * t_dim->w;
1333
638k
                }
1334
343k
                t->bx -= x;
1335
343k
            }
1336
280k
            t->by -= y;
1337
1338
280k
            if (!has_chroma) continue;
1339
1340
236k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
236k
            if (b->uv_mode == CFL_PRED) {
1343
42.2k
                assert(!init_x && !init_y);
1344
1345
42.2k
                int16_t *const ac = t->scratch.ac;
1346
42.2k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
42.2k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
42.2k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
42.2k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
42.2k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
42.2k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
42.2k
                const int furthest_r =
1354
42.2k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
42.2k
                const int furthest_b =
1356
42.2k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
42.2k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
42.2k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
42.2k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
42.2k
                                                         cbw4 * 4, cbh4 * 4);
1361
126k
                for (int pl = 0; pl < 2; pl++) {
1362
84.5k
                    if (!b->cfl_alpha[pl]) continue;
1363
66.3k
                    int angle = 0;
1364
66.3k
                    const pixel *top_sb_edge = NULL;
1365
66.3k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
11.3k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
11.3k
                        const int sby = t->by >> f->sb_shift;
1368
11.3k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
11.3k
                    }
1370
66.3k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
66.3k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
66.3k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
66.3k
                    const enum IntraPredMode m =
1374
66.3k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
66.3k
                                                          ypos, ypos > ystart,
1376
66.3k
                                                          ts->tiling.col_end >> ss_hor,
1377
66.3k
                                                          ts->tiling.row_end >> ss_ver,
1378
66.3k
                                                          0, uv_dst[pl], stride,
1379
66.3k
                                                          top_sb_edge, DC_PRED, &angle,
1380
66.3k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
66.3k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
66.3k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
66.3k
                                           uv_t_dim->w * 4,
1384
66.3k
                                           uv_t_dim->h * 4,
1385
66.3k
                                           ac, b->cfl_alpha[pl]
1386
66.3k
                                           HIGHBD_CALL_SUFFIX);
1387
66.3k
                }
1388
42.2k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
194k
            } else if (b->pal_sz[1]) {
1394
1.69k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.69k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.69k
                const pixel (*pal)[8];
1397
1.69k
                const uint8_t *pal_idx;
1398
1.69k
                if (t->frame_thread.pass) {
1399
1.69k
                    const int p = t->frame_thread.pass & 1;
1400
1.69k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.69k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.69k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.69k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.69k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.69k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.69k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.69k
                                       f->cur.stride[1], pal[1],
1412
1.69k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.69k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.69k
                                       f->cur.stride[1], pal[2],
1415
1.69k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.69k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.69k
            }
1425
1426
236k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
236k
                                 sm_uv_flag(&t->l, cby4);
1428
236k
            const int uv_sb_has_tr =
1429
236k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
228k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
236k
            const int uv_sb_has_bl =
1432
236k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
228k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
236k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
708k
            for (int pl = 0; pl < 2; pl++) {
1436
970k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
498k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
498k
                {
1439
498k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
498k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
498k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.10M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
602k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
602k
                    {
1445
602k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
536k
                            b->pal_sz[1])
1447
69.7k
                        {
1448
69.7k
                            goto skip_uv_pred;
1449
69.7k
                        }
1450
1451
533k
                        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
533k
                        const enum EdgeFlags edge_flags =
1456
533k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
262k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
356k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
533k
                            ((x > (init_x >> ss_hor) ||
1460
429k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
342k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
533k
                        const pixel *top_sb_edge = NULL;
1463
533k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
110k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
110k
                            const int sby = t->by >> f->sb_shift;
1466
110k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
110k
                        }
1468
533k
                        const enum IntraPredMode uv_mode =
1469
533k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
533k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
533k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
533k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
533k
                        const enum IntraPredMode m =
1474
533k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
533k
                                                              ypos, ypos > ystart,
1476
533k
                                                              ts->tiling.col_end >> ss_hor,
1477
533k
                                                              ts->tiling.row_end >> ss_ver,
1478
533k
                                                              edge_flags, dst, stride,
1479
533k
                                                              top_sb_edge, uv_mode,
1480
533k
                                                              &angle, uv_t_dim->w,
1481
533k
                                                              uv_t_dim->h,
1482
533k
                                                              f->seq_hdr->intra_edge_filter,
1483
533k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
533k
                        angle |= intra_edge_filter_flag;
1485
533k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
533k
                                                 uv_t_dim->w * 4,
1487
533k
                                                 uv_t_dim->h * 4,
1488
533k
                                                 angle | sm_uv_fl,
1489
533k
                                                 (4 * f->bw + ss_hor -
1490
533k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
533k
                                                 (4 * f->bh + ss_ver -
1492
533k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
533k
                                                 HIGHBD_CALL_SUFFIX);
1494
533k
                        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
602k
                    skip_uv_pred: {}
1505
602k
                        if (!b->skip) {
1506
237k
                            enum TxfmType txtp;
1507
237k
                            int eob;
1508
237k
                            coef *cf;
1509
237k
                            if (t->frame_thread.pass) {
1510
237k
                                const int p = t->frame_thread.pass & 1;
1511
237k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
237k
                                cf = ts->frame_thread[p].cf;
1513
237k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
237k
                                eob  = cbi >> 5;
1515
237k
                                txtp = cbi & 0x1f;
1516
237k
                            } 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
237k
                            if (eob >= 0) {
1533
72.5k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
72.5k
                                dsp->itx.itxfm_add[b->uvtx]
1537
72.5k
                                                  [txtp](dst, stride,
1538
72.5k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
72.5k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
72.5k
                            }
1543
365k
                        } 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
602k
                        dst += uv_t_dim->w * 4;
1548
602k
                    }
1549
498k
                    t->bx -= x << ss_hor;
1550
498k
                }
1551
471k
                t->by -= y << ss_ver;
1552
471k
            }
1553
236k
        }
1554
270k
    }
1555
265k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
178k
{
1560
178k
    Dav1dTileState *const ts = t->ts;
1561
178k
    const Dav1dFrameContext *const f = t->f;
1562
178k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
178k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
178k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
178k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
178k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
178k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
178k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
178k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
178k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
123k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
117k
                           (bh4 > ss_ver || t->by & 1);
1573
178k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
178k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
178k
    int res;
1576
1577
    // prediction
1578
178k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
178k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
178k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
178k
    const ptrdiff_t uvdstoff =
1582
178k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
178k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
22.4k
        assert(!f->frame_hdr->super_res.enabled);
1586
22.4k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
22.4k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
22.4k
        if (res) return res;
1589
45.3k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
30.2k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
30.2k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
30.2k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
30.2k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
30.2k
            if (res) return res;
1595
30.2k
        }
1596
156k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
133k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
133k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
133k
        if (imin(bw4, bh4) > 1 &&
1601
81.4k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
79.7k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
3.41k
        {
1604
3.41k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
3.41k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
3.41k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
3.41k
            if (res) return res;
1608
130k
        } else {
1609
130k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
130k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
130k
            if (res) return res;
1612
130k
            if (b->motion_mode == MM_OBMC) {
1613
13.8k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
13.8k
                if (res) return res;
1615
13.8k
            }
1616
130k
        }
1617
133k
        if (b->interintra_type) {
1618
2.19k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.19k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.73k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.19k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.19k
            int angle = 0;
1623
2.19k
            const pixel *top_sb_edge = NULL;
1624
2.19k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.19k
                top_sb_edge = f->ipred_edge[0];
1626
1.19k
                const int sby = t->by >> f->sb_shift;
1627
1.19k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.19k
            }
1629
2.19k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.19k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.19k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.19k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.19k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.19k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.19k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.19k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.19k
                                     HIGHBD_CALL_SUFFIX);
1638
2.19k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.19k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.19k
        }
1641
1642
133k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
79.3k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
79.3k
        refmvs_block *const *r;
1647
79.3k
        if (is_sub8x8) {
1648
4.62k
            assert(ss_hor == 1);
1649
4.62k
            r = &t->rt.r[(t->by & 31) + 5];
1650
4.62k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
4.62k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
4.62k
            if (bw4 == 1 && bh4 == ss_ver)
1653
804
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
4.62k
        }
1655
1656
        // chroma prediction
1657
79.3k
        if (is_sub8x8) {
1658
4.61k
            assert(ss_hor == 1);
1659
4.61k
            ptrdiff_t h_off = 0, v_off = 0;
1660
4.61k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
2.38k
                for (int pl = 0; pl < 2; pl++) {
1662
1.59k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.59k
                             NULL, f->cur.stride[1],
1664
1.59k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.59k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.59k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.59k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.59k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.59k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.59k
                    if (res) return res;
1671
1.59k
                }
1672
796
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
796
                h_off = 2;
1674
796
            }
1675
4.61k
            if (bw4 == 1) {
1676
3.69k
                const enum Filter2d left_filter_2d =
1677
3.69k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
11.0k
                for (int pl = 0; pl < 2; pl++) {
1679
7.38k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
7.38k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
7.38k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
7.38k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
7.38k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
7.38k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
7.38k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
7.38k
                    if (res) return res;
1687
7.38k
                }
1688
3.69k
                h_off = 2;
1689
3.69k
            }
1690
4.61k
            if (bh4 == ss_ver) {
1691
1.72k
                const enum Filter2d top_filter_2d =
1692
1.72k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
5.16k
                for (int pl = 0; pl < 2; pl++) {
1694
3.44k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
3.44k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
3.44k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
3.44k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
3.44k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
3.44k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
3.44k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
3.44k
                    if (res) return res;
1702
3.44k
                }
1703
1.72k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
1.72k
            }
1705
13.8k
            for (int pl = 0; pl < 2; pl++) {
1706
9.22k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
9.22k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
9.22k
                         refp, b->ref[0], filter_2d);
1709
9.22k
                if (res) return res;
1710
9.22k
            }
1711
74.7k
        } else {
1712
74.7k
            if (imin(cbw4, cbh4) > 1 &&
1713
37.8k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
36.1k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
3.36k
            {
1716
10.0k
                for (int pl = 0; pl < 2; pl++) {
1717
6.72k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
6.72k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
6.72k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
6.72k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
6.72k
                    if (res) return res;
1722
6.72k
                }
1723
71.4k
            } else {
1724
214k
                for (int pl = 0; pl < 2; pl++) {
1725
142k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
142k
                             NULL, f->cur.stride[1],
1727
142k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
142k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
142k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
142k
                    if (res) return res;
1731
142k
                    if (b->motion_mode == MM_OBMC) {
1732
17.8k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
17.8k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
17.8k
                        if (res) return res;
1735
17.8k
                    }
1736
142k
                }
1737
71.4k
            }
1738
74.7k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
1.76k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
5.29k
                for (int pl = 0; pl < 2; pl++) {
1745
3.53k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
3.53k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
3.53k
                    enum IntraPredMode m =
1748
3.53k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
2.95k
                        SMOOTH_PRED : b->interintra_mode;
1750
3.53k
                    int angle = 0;
1751
3.53k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
3.53k
                    const pixel *top_sb_edge = NULL;
1753
3.53k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.52k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.52k
                        const int sby = t->by >> f->sb_shift;
1756
1.52k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.52k
                    }
1758
3.53k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
3.53k
                                                          (t->bx >> ss_hor) >
1760
3.53k
                                                              (ts->tiling.col_start >> ss_hor),
1761
3.53k
                                                          t->by >> ss_ver,
1762
3.53k
                                                          (t->by >> ss_ver) >
1763
3.53k
                                                              (ts->tiling.row_start >> ss_ver),
1764
3.53k
                                                          ts->tiling.col_end >> ss_hor,
1765
3.53k
                                                          ts->tiling.row_end >> ss_ver,
1766
3.53k
                                                          0, uvdst, f->cur.stride[1],
1767
3.53k
                                                          top_sb_edge, m,
1768
3.53k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
3.53k
                                                          HIGHBD_CALL_SUFFIX);
1770
3.53k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
3.53k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
3.53k
                                             HIGHBD_CALL_SUFFIX);
1773
3.53k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
3.53k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
3.53k
                }
1776
1.76k
            }
1777
74.7k
        }
1778
1779
133k
    skip_inter_chroma_pred: {}
1780
133k
        t->tl_4x4_filter = filter_2d;
1781
133k
    } else {
1782
22.4k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
22.4k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
22.4k
        int jnt_weight;
1786
22.4k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
22.4k
        const uint8_t *mask;
1788
1789
67.3k
        for (int i = 0; i < 2; i++) {
1790
44.8k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
44.8k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.81k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.81k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.81k
                if (res) return res;
1796
42.0k
            } else {
1797
42.0k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
42.0k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
42.0k
                if (res) return res;
1800
42.0k
            }
1801
44.8k
        }
1802
22.4k
        switch (b->comp_type) {
1803
16.7k
        case COMP_INTER_AVG:
1804
16.7k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
16.7k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
16.7k
            break;
1807
2.26k
        case COMP_INTER_WEIGHTED_AVG:
1808
2.26k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
2.26k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
2.26k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
2.26k
            break;
1812
1.85k
        case COMP_INTER_SEG:
1813
1.85k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.85k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.85k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.85k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.85k
            mask = seg_mask;
1818
1.85k
            break;
1819
1.57k
        case COMP_INTER_WEDGE:
1820
1.57k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.57k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.57k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.57k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.57k
            if (has_chroma)
1825
1.03k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.57k
            break;
1827
22.4k
        }
1828
1829
        // chroma
1830
55.4k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
110k
            for (int i = 0; i < 2; i++) {
1832
73.8k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
73.8k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
14.0k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
3.39k
                {
1836
3.39k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
3.39k
                                      b_dim, 1 + pl,
1838
3.39k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
3.39k
                    if (res) return res;
1840
70.4k
                } else {
1841
70.4k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
70.4k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
70.4k
                    if (res) return res;
1844
70.4k
                }
1845
73.8k
            }
1846
36.9k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
36.9k
            switch (b->comp_type) {
1848
28.5k
            case COMP_INTER_AVG:
1849
28.5k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
28.5k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
28.5k
                            HIGHBD_CALL_SUFFIX);
1852
28.5k
                break;
1853
3.19k
            case COMP_INTER_WEIGHTED_AVG:
1854
3.19k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
3.19k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
3.19k
                              HIGHBD_CALL_SUFFIX);
1857
3.19k
                break;
1858
2.07k
            case COMP_INTER_WEDGE:
1859
5.16k
            case COMP_INTER_SEG:
1860
5.16k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
5.16k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
5.16k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
5.16k
                             HIGHBD_CALL_SUFFIX);
1864
5.16k
                break;
1865
36.9k
            }
1866
36.9k
        }
1867
22.4k
    }
1868
1869
178k
    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
178k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
178k
    if (b->skip) {
1882
        // reset coef contexts
1883
67.2k
        BlockContext *const a = t->a;
1884
67.2k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
67.2k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
67.2k
        if (has_chroma) {
1887
29.9k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
29.9k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
29.9k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
29.9k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
29.9k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
29.9k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
29.9k
        }
1894
67.2k
        return 0;
1895
67.2k
    }
1896
1897
111k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
111k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
111k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
230k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
239k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
121k
            int y_off = !!init_y, y;
1905
121k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
254k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
133k
                 y += ytx->h, y_off++)
1908
133k
            {
1909
133k
                int x, x_off = !!init_x;
1910
321k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
188k
                     x += ytx->w, x_off++)
1912
188k
                {
1913
188k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
188k
                                   x_off, y_off, &dst[x * 4]);
1915
188k
                    t->bx += ytx->w;
1916
188k
                }
1917
133k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
133k
                t->bx -= x;
1919
133k
                t->by += ytx->h;
1920
133k
            }
1921
121k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
121k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
275k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
183k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
183k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
183k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
401k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
217k
                {
1931
217k
                    int x;
1932
217k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
553k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
335k
                    {
1935
335k
                        coef *cf;
1936
335k
                        int eob;
1937
335k
                        enum TxfmType txtp;
1938
335k
                        if (t->frame_thread.pass) {
1939
335k
                            const int p = t->frame_thread.pass & 1;
1940
335k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
335k
                            cf = ts->frame_thread[p].cf;
1942
335k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
335k
                            eob  = cbi >> 5;
1944
335k
                            txtp = cbi & 0x1f;
1945
335k
                        } else {
1946
1
                            uint8_t cf_ctx;
1947
1
                            cf = bitfn(t->cf);
1948
1
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
1
                                                        bx4 + (x << ss_hor)];
1950
1
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
1
                                               &t->l.ccoef[pl][cby4 + y],
1952
1
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
1
                                               cf, &txtp, &cf_ctx);
1954
1
                            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
1
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
1
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
1
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
1
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
1
                        }
1963
335k
                        if (eob >= 0) {
1964
119k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
119k
                            dsp->itx.itxfm_add[b->uvtx]
1967
119k
                                              [txtp](&uvdst[4 * x],
1968
119k
                                                     f->cur.stride[1],
1969
119k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
119k
                            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
119k
                        }
1974
335k
                        t->bx += uvtx->w << ss_hor;
1975
335k
                    }
1976
217k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
217k
                    t->bx -= x << ss_hor;
1978
217k
                    t->by += uvtx->h << ss_ver;
1979
217k
                }
1980
183k
                t->by -= y << ss_ver;
1981
183k
            }
1982
121k
        }
1983
118k
    }
1984
111k
    return 0;
1985
178k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
78.0k
{
1560
78.0k
    Dav1dTileState *const ts = t->ts;
1561
78.0k
    const Dav1dFrameContext *const f = t->f;
1562
78.0k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
78.0k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
78.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
78.0k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
78.0k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
78.0k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
78.0k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
78.0k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
78.0k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
68.9k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
64.3k
                           (bh4 > ss_ver || t->by & 1);
1573
78.0k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
78.0k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
78.0k
    int res;
1576
1577
    // prediction
1578
78.0k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
78.0k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
78.0k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
78.0k
    const ptrdiff_t uvdstoff =
1582
78.0k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
78.0k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
10.3k
        assert(!f->frame_hdr->super_res.enabled);
1586
10.3k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
10.3k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
10.3k
        if (res) return res;
1589
15.7k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
10.4k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
10.4k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
10.4k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
10.4k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
10.4k
            if (res) return res;
1595
10.4k
        }
1596
67.6k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
56.1k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
56.1k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
56.1k
        if (imin(bw4, bh4) > 1 &&
1601
34.0k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
32.7k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.00k
        {
1604
2.00k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.00k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.00k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.00k
            if (res) return res;
1608
54.1k
        } else {
1609
54.1k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
54.1k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
54.1k
            if (res) return res;
1612
54.1k
            if (b->motion_mode == MM_OBMC) {
1613
5.13k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
5.13k
                if (res) return res;
1615
5.13k
            }
1616
54.1k
        }
1617
56.1k
        if (b->interintra_type) {
1618
1.35k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
1.35k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
991
                                   SMOOTH_PRED : b->interintra_mode;
1621
1.35k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
1.35k
            int angle = 0;
1623
1.35k
            const pixel *top_sb_edge = NULL;
1624
1.35k
            if (!(t->by & (f->sb_step - 1))) {
1625
778
                top_sb_edge = f->ipred_edge[0];
1626
778
                const int sby = t->by >> f->sb_shift;
1627
778
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
778
            }
1629
1.35k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
1.35k
                                                  t->by, t->by > ts->tiling.row_start,
1631
1.35k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
1.35k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
1.35k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
1.35k
                                                  HIGHBD_CALL_SUFFIX);
1635
1.35k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
1.35k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
1.35k
                                     HIGHBD_CALL_SUFFIX);
1638
1.35k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
1.35k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
1.35k
        }
1641
1642
56.1k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
47.1k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
47.1k
        refmvs_block *const *r;
1647
47.1k
        if (is_sub8x8) {
1648
3.47k
            assert(ss_hor == 1);
1649
3.47k
            r = &t->rt.r[(t->by & 31) + 5];
1650
3.47k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
3.47k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
3.47k
            if (bw4 == 1 && bh4 == ss_ver)
1653
394
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
3.47k
        }
1655
1656
        // chroma prediction
1657
47.1k
        if (is_sub8x8) {
1658
3.45k
            assert(ss_hor == 1);
1659
3.45k
            ptrdiff_t h_off = 0, v_off = 0;
1660
3.45k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.15k
                for (int pl = 0; pl < 2; pl++) {
1662
772
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
772
                             NULL, f->cur.stride[1],
1664
772
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
772
                             r[-1][t->bx - 1].mv.mv[0],
1666
772
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
772
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
772
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
772
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
772
                    if (res) return res;
1671
772
                }
1672
386
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
386
                h_off = 2;
1674
386
            }
1675
3.45k
            if (bw4 == 1) {
1676
2.92k
                const enum Filter2d left_filter_2d =
1677
2.92k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
8.77k
                for (int pl = 0; pl < 2; pl++) {
1679
5.84k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
5.84k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
5.84k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
5.84k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
5.84k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
5.84k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
5.84k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
5.84k
                    if (res) return res;
1687
5.84k
                }
1688
2.92k
                h_off = 2;
1689
2.92k
            }
1690
3.45k
            if (bh4 == ss_ver) {
1691
921
                const enum Filter2d top_filter_2d =
1692
921
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
2.76k
                for (int pl = 0; pl < 2; pl++) {
1694
1.84k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
1.84k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
1.84k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
1.84k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
1.84k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
1.84k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
1.84k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
1.84k
                    if (res) return res;
1702
1.84k
                }
1703
921
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
921
            }
1705
10.3k
            for (int pl = 0; pl < 2; pl++) {
1706
6.91k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
6.91k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
6.91k
                         refp, b->ref[0], filter_2d);
1709
6.91k
                if (res) return res;
1710
6.91k
            }
1711
43.7k
        } else {
1712
43.7k
            if (imin(cbw4, cbh4) > 1 &&
1713
21.6k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
20.3k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.96k
            {
1716
5.90k
                for (int pl = 0; pl < 2; pl++) {
1717
3.93k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
3.93k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
3.93k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
3.93k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
3.93k
                    if (res) return res;
1722
3.93k
                }
1723
41.7k
            } else {
1724
125k
                for (int pl = 0; pl < 2; pl++) {
1725
83.5k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
83.5k
                             NULL, f->cur.stride[1],
1727
83.5k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
83.5k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
83.5k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
83.5k
                    if (res) return res;
1731
83.5k
                    if (b->motion_mode == MM_OBMC) {
1732
10.0k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
10.0k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
10.0k
                        if (res) return res;
1735
10.0k
                    }
1736
83.5k
                }
1737
41.7k
            }
1738
43.7k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
977
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
2.93k
                for (int pl = 0; pl < 2; pl++) {
1745
1.95k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.95k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.95k
                    enum IntraPredMode m =
1748
1.95k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.52k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.95k
                    int angle = 0;
1751
1.95k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.95k
                    const pixel *top_sb_edge = NULL;
1753
1.95k
                    if (!(t->by & (f->sb_step - 1))) {
1754
796
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
796
                        const int sby = t->by >> f->sb_shift;
1756
796
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
796
                    }
1758
1.95k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.95k
                                                          (t->bx >> ss_hor) >
1760
1.95k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.95k
                                                          t->by >> ss_ver,
1762
1.95k
                                                          (t->by >> ss_ver) >
1763
1.95k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.95k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.95k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.95k
                                                          0, uvdst, f->cur.stride[1],
1767
1.95k
                                                          top_sb_edge, m,
1768
1.95k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.95k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.95k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.95k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.95k
                                             HIGHBD_CALL_SUFFIX);
1773
1.95k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.95k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.95k
                }
1776
977
            }
1777
43.7k
        }
1778
1779
56.1k
    skip_inter_chroma_pred: {}
1780
56.1k
        t->tl_4x4_filter = filter_2d;
1781
56.1k
    } else {
1782
11.4k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
11.4k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
11.4k
        int jnt_weight;
1786
11.4k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
11.4k
        const uint8_t *mask;
1788
1789
34.4k
        for (int i = 0; i < 2; i++) {
1790
22.9k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
22.9k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.34k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.34k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.34k
                if (res) return res;
1796
21.5k
            } else {
1797
21.5k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
21.5k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
21.5k
                if (res) return res;
1800
21.5k
            }
1801
22.9k
        }
1802
11.4k
        switch (b->comp_type) {
1803
9.27k
        case COMP_INTER_AVG:
1804
9.27k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
9.27k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
9.27k
            break;
1807
601
        case COMP_INTER_WEIGHTED_AVG:
1808
601
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
601
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
601
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
601
            break;
1812
651
        case COMP_INTER_SEG:
1813
651
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
651
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
651
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
651
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
651
            mask = seg_mask;
1818
651
            break;
1819
940
        case COMP_INTER_WEDGE:
1820
940
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
940
            dsp->mc.mask(dst, f->cur.stride[0],
1822
940
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
940
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
940
            if (has_chroma)
1825
789
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
940
            break;
1827
11.4k
        }
1828
1829
        // chroma
1830
29.6k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
59.3k
            for (int i = 0; i < 2; i++) {
1832
39.5k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
39.5k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
7.99k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.40k
                {
1836
1.40k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.40k
                                      b_dim, 1 + pl,
1838
1.40k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.40k
                    if (res) return res;
1840
38.1k
                } else {
1841
38.1k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
38.1k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
38.1k
                    if (res) return res;
1844
38.1k
                }
1845
39.5k
            }
1846
19.7k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
19.7k
            switch (b->comp_type) {
1848
16.8k
            case COMP_INTER_AVG:
1849
16.8k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
16.8k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
16.8k
                            HIGHBD_CALL_SUFFIX);
1852
16.8k
                break;
1853
170
            case COMP_INTER_WEIGHTED_AVG:
1854
170
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
170
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
170
                              HIGHBD_CALL_SUFFIX);
1857
170
                break;
1858
1.57k
            case COMP_INTER_WEDGE:
1859
2.78k
            case COMP_INTER_SEG:
1860
2.78k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.78k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.78k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.78k
                             HIGHBD_CALL_SUFFIX);
1864
2.78k
                break;
1865
19.7k
            }
1866
19.7k
        }
1867
11.4k
    }
1868
1869
78.0k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
78.0k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
78.0k
    if (b->skip) {
1882
        // reset coef contexts
1883
23.4k
        BlockContext *const a = t->a;
1884
23.4k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
23.4k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
23.4k
        if (has_chroma) {
1887
18.6k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
18.6k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
18.6k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
18.6k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
18.6k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
18.6k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
18.6k
        }
1894
23.4k
        return 0;
1895
23.4k
    }
1896
1897
54.5k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
54.5k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
54.5k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
112k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
118k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
60.1k
            int y_off = !!init_y, y;
1905
60.1k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
125k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
65.1k
                 y += ytx->h, y_off++)
1908
65.1k
            {
1909
65.1k
                int x, x_off = !!init_x;
1910
150k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
85.6k
                     x += ytx->w, x_off++)
1912
85.6k
                {
1913
85.6k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
85.6k
                                   x_off, y_off, &dst[x * 4]);
1915
85.6k
                    t->bx += ytx->w;
1916
85.6k
                }
1917
65.1k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
65.1k
                t->bx -= x;
1919
65.1k
                t->by += ytx->h;
1920
65.1k
            }
1921
60.1k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
60.1k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
145k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
96.9k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
96.9k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
96.9k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
209k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
112k
                {
1931
112k
                    int x;
1932
112k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
271k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
158k
                    {
1935
158k
                        coef *cf;
1936
158k
                        int eob;
1937
158k
                        enum TxfmType txtp;
1938
158k
                        if (t->frame_thread.pass) {
1939
158k
                            const int p = t->frame_thread.pass & 1;
1940
158k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
158k
                            cf = ts->frame_thread[p].cf;
1942
158k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
158k
                            eob  = cbi >> 5;
1944
158k
                            txtp = cbi & 0x1f;
1945
158k
                        } 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
158k
                        if (eob >= 0) {
1964
48.2k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
48.2k
                            dsp->itx.itxfm_add[b->uvtx]
1967
48.2k
                                              [txtp](&uvdst[4 * x],
1968
48.2k
                                                     f->cur.stride[1],
1969
48.2k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
48.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
48.2k
                        }
1974
158k
                        t->bx += uvtx->w << ss_hor;
1975
158k
                    }
1976
112k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
112k
                    t->bx -= x << ss_hor;
1978
112k
                    t->by += uvtx->h << ss_ver;
1979
112k
                }
1980
96.9k
                t->by -= y << ss_ver;
1981
96.9k
            }
1982
60.1k
        }
1983
58.2k
    }
1984
54.5k
    return 0;
1985
78.0k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
100k
{
1560
100k
    Dav1dTileState *const ts = t->ts;
1561
100k
    const Dav1dFrameContext *const f = t->f;
1562
100k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
100k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
100k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
100k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
100k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
100k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
100k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
100k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
100k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
54.8k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
52.7k
                           (bh4 > ss_ver || t->by & 1);
1573
100k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
100k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
100k
    int res;
1576
1577
    // prediction
1578
100k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
100k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
100k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
100k
    const ptrdiff_t uvdstoff =
1582
100k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
100k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
12.0k
        assert(!f->frame_hdr->super_res.enabled);
1586
12.0k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
12.0k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
12.0k
        if (res) return res;
1589
29.6k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
19.7k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
19.7k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
19.7k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
19.7k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
19.7k
            if (res) return res;
1595
19.7k
        }
1596
88.6k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
77.6k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
77.6k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
77.6k
        if (imin(bw4, bh4) > 1 &&
1601
47.4k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
46.9k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.41k
        {
1604
1.41k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.41k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.41k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.41k
            if (res) return res;
1608
76.2k
        } else {
1609
76.2k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
76.2k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
76.2k
            if (res) return res;
1612
76.2k
            if (b->motion_mode == MM_OBMC) {
1613
8.76k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
8.76k
                if (res) return res;
1615
8.76k
            }
1616
76.2k
        }
1617
77.6k
        if (b->interintra_type) {
1618
838
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
838
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
748
                                   SMOOTH_PRED : b->interintra_mode;
1621
838
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
838
            int angle = 0;
1623
838
            const pixel *top_sb_edge = NULL;
1624
838
            if (!(t->by & (f->sb_step - 1))) {
1625
414
                top_sb_edge = f->ipred_edge[0];
1626
414
                const int sby = t->by >> f->sb_shift;
1627
414
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
414
            }
1629
838
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
838
                                                  t->by, t->by > ts->tiling.row_start,
1631
838
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
838
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
838
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
838
                                                  HIGHBD_CALL_SUFFIX);
1635
838
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
838
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
838
                                     HIGHBD_CALL_SUFFIX);
1638
838
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
838
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
838
        }
1641
1642
77.6k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
32.2k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
32.2k
        refmvs_block *const *r;
1647
32.2k
        if (is_sub8x8) {
1648
1.15k
            assert(ss_hor == 1);
1649
1.15k
            r = &t->rt.r[(t->by & 31) + 5];
1650
1.15k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
1.15k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
1.15k
            if (bw4 == 1 && bh4 == ss_ver)
1653
410
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
1.15k
        }
1655
1656
        // chroma prediction
1657
32.2k
        if (is_sub8x8) {
1658
1.15k
            assert(ss_hor == 1);
1659
1.15k
            ptrdiff_t h_off = 0, v_off = 0;
1660
1.15k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.23k
                for (int pl = 0; pl < 2; pl++) {
1662
820
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
820
                             NULL, f->cur.stride[1],
1664
820
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
820
                             r[-1][t->bx - 1].mv.mv[0],
1666
820
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
820
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
820
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
820
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
820
                    if (res) return res;
1671
820
                }
1672
410
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
410
                h_off = 2;
1674
410
            }
1675
1.15k
            if (bw4 == 1) {
1676
766
                const enum Filter2d left_filter_2d =
1677
766
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
2.29k
                for (int pl = 0; pl < 2; pl++) {
1679
1.53k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
1.53k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
1.53k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
1.53k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
1.53k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
1.53k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
1.53k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
1.53k
                    if (res) return res;
1687
1.53k
                }
1688
766
                h_off = 2;
1689
766
            }
1690
1.15k
            if (bh4 == ss_ver) {
1691
800
                const enum Filter2d top_filter_2d =
1692
800
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
2.39k
                for (int pl = 0; pl < 2; pl++) {
1694
1.59k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
1.59k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
1.59k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
1.59k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
1.59k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
1.59k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
1.59k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
1.59k
                    if (res) return res;
1702
1.59k
                }
1703
800
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
800
            }
1705
3.46k
            for (int pl = 0; pl < 2; pl++) {
1706
2.31k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
2.31k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
2.31k
                         refp, b->ref[0], filter_2d);
1709
2.31k
                if (res) return res;
1710
2.31k
            }
1711
31.0k
        } else {
1712
31.0k
            if (imin(cbw4, cbh4) > 1 &&
1713
16.2k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
15.8k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.39k
            {
1716
4.18k
                for (int pl = 0; pl < 2; pl++) {
1717
2.78k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
2.78k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
2.78k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
2.78k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
2.78k
                    if (res) return res;
1722
2.78k
                }
1723
29.6k
            } else {
1724
88.9k
                for (int pl = 0; pl < 2; pl++) {
1725
59.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
59.3k
                             NULL, f->cur.stride[1],
1727
59.3k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
59.3k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
59.3k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
59.3k
                    if (res) return res;
1731
59.3k
                    if (b->motion_mode == MM_OBMC) {
1732
7.73k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
7.73k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
7.73k
                        if (res) return res;
1735
7.73k
                    }
1736
59.3k
                }
1737
29.6k
            }
1738
31.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
788
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
2.36k
                for (int pl = 0; pl < 2; pl++) {
1745
1.57k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
1.57k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
1.57k
                    enum IntraPredMode m =
1748
1.57k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
1.42k
                        SMOOTH_PRED : b->interintra_mode;
1750
1.57k
                    int angle = 0;
1751
1.57k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
1.57k
                    const pixel *top_sb_edge = NULL;
1753
1.57k
                    if (!(t->by & (f->sb_step - 1))) {
1754
728
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
728
                        const int sby = t->by >> f->sb_shift;
1756
728
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
728
                    }
1758
1.57k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
1.57k
                                                          (t->bx >> ss_hor) >
1760
1.57k
                                                              (ts->tiling.col_start >> ss_hor),
1761
1.57k
                                                          t->by >> ss_ver,
1762
1.57k
                                                          (t->by >> ss_ver) >
1763
1.57k
                                                              (ts->tiling.row_start >> ss_ver),
1764
1.57k
                                                          ts->tiling.col_end >> ss_hor,
1765
1.57k
                                                          ts->tiling.row_end >> ss_ver,
1766
1.57k
                                                          0, uvdst, f->cur.stride[1],
1767
1.57k
                                                          top_sb_edge, m,
1768
1.57k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
1.57k
                                                          HIGHBD_CALL_SUFFIX);
1770
1.57k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
1.57k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
1.57k
                                             HIGHBD_CALL_SUFFIX);
1773
1.57k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
1.57k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
1.57k
                }
1776
788
            }
1777
31.0k
        }
1778
1779
77.6k
    skip_inter_chroma_pred: {}
1780
77.6k
        t->tl_4x4_filter = filter_2d;
1781
77.6k
    } else {
1782
10.9k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
10.9k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
10.9k
        int jnt_weight;
1786
10.9k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
10.9k
        const uint8_t *mask;
1788
1789
32.9k
        for (int i = 0; i < 2; i++) {
1790
21.9k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
21.9k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.46k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.46k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.46k
                if (res) return res;
1796
20.4k
            } else {
1797
20.4k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
20.4k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
20.4k
                if (res) return res;
1800
20.4k
            }
1801
21.9k
        }
1802
10.9k
        switch (b->comp_type) {
1803
7.48k
        case COMP_INTER_AVG:
1804
7.48k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
7.48k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
7.48k
            break;
1807
1.66k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.66k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.66k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.66k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.66k
            break;
1812
1.20k
        case COMP_INTER_SEG:
1813
1.20k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.20k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.20k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.20k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.20k
            mask = seg_mask;
1818
1.20k
            break;
1819
632
        case COMP_INTER_WEDGE:
1820
632
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
632
            dsp->mc.mask(dst, f->cur.stride[0],
1822
632
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
632
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
632
            if (has_chroma)
1825
246
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
632
            break;
1827
10.9k
        }
1828
1829
        // chroma
1830
25.7k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
51.4k
            for (int i = 0; i < 2; i++) {
1832
34.3k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
34.3k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
6.08k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.99k
                {
1836
1.99k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.99k
                                      b_dim, 1 + pl,
1838
1.99k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.99k
                    if (res) return res;
1840
32.3k
                } else {
1841
32.3k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
32.3k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
32.3k
                    if (res) return res;
1844
32.3k
                }
1845
34.3k
            }
1846
17.1k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
17.1k
            switch (b->comp_type) {
1848
11.7k
            case COMP_INTER_AVG:
1849
11.7k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
11.7k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
11.7k
                            HIGHBD_CALL_SUFFIX);
1852
11.7k
                break;
1853
3.02k
            case COMP_INTER_WEIGHTED_AVG:
1854
3.02k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
3.02k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
3.02k
                              HIGHBD_CALL_SUFFIX);
1857
3.02k
                break;
1858
492
            case COMP_INTER_WEDGE:
1859
2.38k
            case COMP_INTER_SEG:
1860
2.38k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.38k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.38k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.38k
                             HIGHBD_CALL_SUFFIX);
1864
2.38k
                break;
1865
17.1k
            }
1866
17.1k
        }
1867
10.9k
    }
1868
1869
100k
    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
100k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
100k
    if (b->skip) {
1882
        // reset coef contexts
1883
43.7k
        BlockContext *const a = t->a;
1884
43.7k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
43.7k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
43.7k
        if (has_chroma) {
1887
11.2k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
11.2k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
11.2k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
11.2k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
11.2k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
11.2k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
11.2k
        }
1894
43.7k
        return 0;
1895
43.7k
    }
1896
1897
56.9k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
56.9k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
56.9k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
117k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
121k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
61.1k
            int y_off = !!init_y, y;
1905
61.1k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
129k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
68.4k
                 y += ytx->h, y_off++)
1908
68.4k
            {
1909
68.4k
                int x, x_off = !!init_x;
1910
171k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
102k
                     x += ytx->w, x_off++)
1912
102k
                {
1913
102k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
102k
                                   x_off, y_off, &dst[x * 4]);
1915
102k
                    t->bx += ytx->w;
1916
102k
                }
1917
68.4k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
68.4k
                t->bx -= x;
1919
68.4k
                t->by += ytx->h;
1920
68.4k
            }
1921
61.1k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
61.1k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
129k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
86.6k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
86.6k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
86.6k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
191k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
104k
                {
1931
104k
                    int x;
1932
104k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
281k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
176k
                    {
1935
176k
                        coef *cf;
1936
176k
                        int eob;
1937
176k
                        enum TxfmType txtp;
1938
176k
                        if (t->frame_thread.pass) {
1939
176k
                            const int p = t->frame_thread.pass & 1;
1940
176k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
176k
                            cf = ts->frame_thread[p].cf;
1942
176k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
176k
                            eob  = cbi >> 5;
1944
176k
                            txtp = cbi & 0x1f;
1945
176k
                        } else {
1946
1
                            uint8_t cf_ctx;
1947
1
                            cf = bitfn(t->cf);
1948
1
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
1
                                                        bx4 + (x << ss_hor)];
1950
1
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
1
                                               &t->l.ccoef[pl][cby4 + y],
1952
1
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
1
                                               cf, &txtp, &cf_ctx);
1954
1
                            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
1
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
1
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
1
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
1
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
1
                        }
1963
176k
                        if (eob >= 0) {
1964
71.6k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
71.6k
                            dsp->itx.itxfm_add[b->uvtx]
1967
71.6k
                                              [txtp](&uvdst[4 * x],
1968
71.6k
                                                     f->cur.stride[1],
1969
71.6k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
71.6k
                            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
71.6k
                        }
1974
176k
                        t->bx += uvtx->w << ss_hor;
1975
176k
                    }
1976
104k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
104k
                    t->bx -= x << ss_hor;
1978
104k
                    t->by += uvtx->h << ss_ver;
1979
104k
                }
1980
86.6k
                t->by -= y << ss_ver;
1981
86.6k
            }
1982
61.1k
        }
1983
60.3k
    }
1984
56.9k
    return 0;
1985
100k
}
1986
1987
77.0k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
77.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
77.0k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
77.0k
    const int y = sby * f->sb_step * 4;
1994
77.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
77.0k
    pixel *const p[3] = {
1996
77.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
77.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
77.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
77.0k
    };
2000
77.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
77.0k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
77.0k
                                        f->lf.start_of_tile_row[sby]);
2003
77.0k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
42.0k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
42.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
42.0k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
42.0k
    const int y = sby * f->sb_step * 4;
1994
42.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
42.0k
    pixel *const p[3] = {
1996
42.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
42.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
42.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
42.0k
    };
2000
42.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
42.0k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
42.0k
                                        f->lf.start_of_tile_row[sby]);
2003
42.0k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
34.9k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
34.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
34.9k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
34.9k
    const int y = sby * f->sb_step * 4;
1994
34.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
34.9k
    pixel *const p[3] = {
1996
34.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
34.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
34.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
34.9k
    };
2000
34.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
34.9k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
34.9k
                                        f->lf.start_of_tile_row[sby]);
2003
34.9k
}
2004
2005
78.7k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
78.7k
    const int y = sby * f->sb_step * 4;
2007
78.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
78.7k
    pixel *const p[3] = {
2009
78.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
78.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
78.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
78.7k
    };
2013
78.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
78.7k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
78.7k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
76.9k
    {
2017
76.9k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
76.9k
    }
2019
78.7k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
65.1k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
65.1k
    }
2023
78.7k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
43.4k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
43.4k
    const int y = sby * f->sb_step * 4;
2007
43.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
43.4k
    pixel *const p[3] = {
2009
43.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
43.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
43.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
43.4k
    };
2013
43.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
43.4k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
43.4k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
42.0k
    {
2017
42.0k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
42.0k
    }
2019
43.4k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
34.6k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
34.6k
    }
2023
43.4k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
35.3k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
35.3k
    const int y = sby * f->sb_step * 4;
2007
35.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
35.3k
    pixel *const p[3] = {
2009
35.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
35.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
35.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
35.3k
    };
2013
35.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
35.3k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
35.3k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
34.9k
    {
2017
34.9k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
34.9k
    }
2019
35.3k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
30.5k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
30.5k
    }
2023
35.3k
}
2024
2025
42.4k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
42.4k
    const Dav1dFrameContext *const f = tc->f;
2027
42.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
42.4k
    const int sbsz = f->sb_step;
2029
42.4k
    const int y = sby * sbsz * 4;
2030
42.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
42.4k
    pixel *const p[3] = {
2032
42.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
42.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
42.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
42.4k
    };
2036
42.4k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
42.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
42.4k
    const int start = sby * sbsz;
2039
42.4k
    if (sby) {
2040
5.71k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
5.71k
        pixel *p_up[3] = {
2042
5.71k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
5.71k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
5.71k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
5.71k
        };
2046
5.71k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
5.71k
    }
2048
42.4k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
42.4k
    const int end = imin(start + n_blks, f->bh);
2050
42.4k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
42.4k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
21.0k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
21.0k
    const Dav1dFrameContext *const f = tc->f;
2027
21.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
21.0k
    const int sbsz = f->sb_step;
2029
21.0k
    const int y = sby * sbsz * 4;
2030
21.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
21.0k
    pixel *const p[3] = {
2032
21.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
21.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
21.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
21.0k
    };
2036
21.0k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
21.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
21.0k
    const int start = sby * sbsz;
2039
21.0k
    if (sby) {
2040
4.16k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
4.16k
        pixel *p_up[3] = {
2042
4.16k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
4.16k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
4.16k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
4.16k
        };
2046
4.16k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
4.16k
    }
2048
21.0k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
21.0k
    const int end = imin(start + n_blks, f->bh);
2050
21.0k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
21.0k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
21.3k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
21.3k
    const Dav1dFrameContext *const f = tc->f;
2027
21.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
21.3k
    const int sbsz = f->sb_step;
2029
21.3k
    const int y = sby * sbsz * 4;
2030
21.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
21.3k
    pixel *const p[3] = {
2032
21.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
21.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
21.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
21.3k
    };
2036
21.3k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
21.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
21.3k
    const int start = sby * sbsz;
2039
21.3k
    if (sby) {
2040
1.54k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
1.54k
        pixel *p_up[3] = {
2042
1.54k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
1.54k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
1.54k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
1.54k
        };
2046
1.54k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
1.54k
    }
2048
21.3k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
21.3k
    const int end = imin(start + n_blks, f->bh);
2050
21.3k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
21.3k
}
2052
2053
4.83k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
4.83k
    const int sbsz = f->sb_step;
2055
4.83k
    const int y = sby * sbsz * 4;
2056
4.83k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
4.83k
    const pixel *const p[3] = {
2058
4.83k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
4.83k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
4.83k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
4.83k
    };
2062
4.83k
    pixel *const sr_p[3] = {
2063
4.83k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
4.83k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
4.83k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
4.83k
    };
2067
4.83k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
13.8k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
8.97k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
8.97k
        const int h_start = 8 * !!sby >> ss_ver;
2071
8.97k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
8.97k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
8.97k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
8.97k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
8.97k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
8.97k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
8.97k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
8.97k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
8.97k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
8.97k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
8.97k
                          imin(img_h, h_end) + h_start, src_w,
2083
8.97k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
8.97k
                          HIGHBD_CALL_SUFFIX);
2085
8.97k
    }
2086
4.83k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
3.56k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
3.56k
    const int sbsz = f->sb_step;
2055
3.56k
    const int y = sby * sbsz * 4;
2056
3.56k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
3.56k
    const pixel *const p[3] = {
2058
3.56k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
3.56k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
3.56k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
3.56k
    };
2062
3.56k
    pixel *const sr_p[3] = {
2063
3.56k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
3.56k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
3.56k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
3.56k
    };
2067
3.56k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
9.51k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
5.94k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
5.94k
        const int h_start = 8 * !!sby >> ss_ver;
2071
5.94k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
5.94k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
5.94k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
5.94k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
5.94k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
5.94k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
5.94k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
5.94k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
5.94k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
5.94k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
5.94k
                          imin(img_h, h_end) + h_start, src_w,
2083
5.94k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
5.94k
                          HIGHBD_CALL_SUFFIX);
2085
5.94k
    }
2086
3.56k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
1.26k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
1.26k
    const int sbsz = f->sb_step;
2055
1.26k
    const int y = sby * sbsz * 4;
2056
1.26k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
1.26k
    const pixel *const p[3] = {
2058
1.26k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
1.26k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
1.26k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
1.26k
    };
2062
1.26k
    pixel *const sr_p[3] = {
2063
1.26k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
1.26k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
1.26k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
1.26k
    };
2067
1.26k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
4.29k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
3.02k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
3.02k
        const int h_start = 8 * !!sby >> ss_ver;
2071
3.02k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
3.02k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
3.02k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
3.02k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
3.02k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
3.02k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
3.02k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
3.02k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
3.02k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
3.02k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
3.02k
                          imin(img_h, h_end) + h_start, src_w,
2083
3.02k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
3.02k
                          HIGHBD_CALL_SUFFIX);
2085
3.02k
    }
2086
1.26k
}
2087
2088
48.0k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
48.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
48.0k
    const int y = sby * f->sb_step * 4;
2091
48.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
48.0k
    pixel *const sr_p[3] = {
2093
48.0k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
48.0k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
48.0k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
48.0k
    };
2097
48.0k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
48.0k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
27.6k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
27.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
27.6k
    const int y = sby * f->sb_step * 4;
2091
27.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
27.6k
    pixel *const sr_p[3] = {
2093
27.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
27.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
27.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
27.6k
    };
2097
27.6k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
27.6k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
20.3k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
20.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
20.3k
    const int y = sby * f->sb_step * 4;
2091
20.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
20.3k
    pixel *const sr_p[3] = {
2093
20.3k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
20.3k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
20.3k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
20.3k
    };
2097
20.3k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
20.3k
}
2099
2100
0
void bytefn(dav1d_filter_sbrow)(Dav1dFrameContext *const f, const int sby) {
2101
0
    bytefn(dav1d_filter_sbrow_deblock_cols)(f, sby);
2102
0
    bytefn(dav1d_filter_sbrow_deblock_rows)(f, sby);
2103
0
    if (f->seq_hdr->cdef)
2104
0
        bytefn(dav1d_filter_sbrow_cdef)(f->c->tc, sby);
2105
0
    if (f->frame_hdr->width[0] != f->frame_hdr->width[1])
2106
0
        bytefn(dav1d_filter_sbrow_resize)(f, sby);
2107
0
    if (f->lf.restore_planes)
2108
0
        bytefn(dav1d_filter_sbrow_lr)(f, sby);
2109
0
}
Unexecuted instantiation: dav1d_filter_sbrow_8bpc
Unexecuted instantiation: dav1d_filter_sbrow_16bpc
2110
2111
81.2k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
81.2k
    const Dav1dFrameContext *const f = t->f;
2113
81.2k
    Dav1dTileState *const ts = t->ts;
2114
81.2k
    const int sby = t->by >> f->sb_shift;
2115
81.2k
    const int sby_off = f->sb128w * 128 * sby;
2116
81.2k
    const int x_off = ts->tiling.col_start;
2117
2118
81.2k
    const pixel *const y =
2119
81.2k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
81.2k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
81.2k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
81.2k
               4 * (ts->tiling.col_end - x_off));
2123
2124
81.2k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
58.3k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
58.3k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
58.3k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
58.3k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
175k
        for (int pl = 1; pl <= 2; pl++)
2131
116k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
73.3k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
73.3k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
58.3k
    }
2135
81.2k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
44.6k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
44.6k
    const Dav1dFrameContext *const f = t->f;
2113
44.6k
    Dav1dTileState *const ts = t->ts;
2114
44.6k
    const int sby = t->by >> f->sb_shift;
2115
44.6k
    const int sby_off = f->sb128w * 128 * sby;
2116
44.6k
    const int x_off = ts->tiling.col_start;
2117
2118
44.6k
    const pixel *const y =
2119
44.6k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
44.6k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
44.6k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
44.6k
               4 * (ts->tiling.col_end - x_off));
2123
2124
44.6k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
36.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
36.6k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
36.6k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
36.6k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
110k
        for (int pl = 1; pl <= 2; pl++)
2131
73.3k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
73.3k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
73.3k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
36.6k
    }
2135
44.6k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
36.5k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
36.5k
    const Dav1dFrameContext *const f = t->f;
2113
36.5k
    Dav1dTileState *const ts = t->ts;
2114
36.5k
    const int sby = t->by >> f->sb_shift;
2115
36.5k
    const int sby_off = f->sb128w * 128 * sby;
2116
36.5k
    const int x_off = ts->tiling.col_start;
2117
2118
36.5k
    const pixel *const y =
2119
36.5k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
36.5k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
36.5k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
36.5k
               4 * (ts->tiling.col_end - x_off));
2123
2124
36.5k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
21.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
21.6k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
21.6k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
21.6k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
64.9k
        for (int pl = 1; pl <= 2; pl++)
2131
43.3k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
21.6k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
21.6k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
21.6k
    }
2135
36.5k
}
2136
2137
void bytefn(dav1d_copy_pal_block_y)(Dav1dTaskContext *const t,
2138
                                    const int bx4, const int by4,
2139
                                    const int bw4, const int bh4)
2140
2141
9.18k
{
2142
9.18k
    const Dav1dFrameContext *const f = t->f;
2143
9.18k
    pixel *const pal = t->frame_thread.pass ?
2144
9.18k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
9.18k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
9.18k
        bytefn(t->scratch.pal)[0];
2147
42.7k
    for (int x = 0; x < bw4; x++)
2148
33.5k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
36.9k
    for (int y = 0; y < bh4; y++)
2150
27.7k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
9.18k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
4.63k
{
2142
4.63k
    const Dav1dFrameContext *const f = t->f;
2143
4.63k
    pixel *const pal = t->frame_thread.pass ?
2144
4.63k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
4.63k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
4.63k
        bytefn(t->scratch.pal)[0];
2147
18.8k
    for (int x = 0; x < bw4; x++)
2148
14.2k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
17.3k
    for (int y = 0; y < bh4; y++)
2150
12.6k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
4.63k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
4.55k
{
2142
4.55k
    const Dav1dFrameContext *const f = t->f;
2143
4.55k
    pixel *const pal = t->frame_thread.pass ?
2144
4.55k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
4.55k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
4.55k
        bytefn(t->scratch.pal)[0];
2147
23.8k
    for (int x = 0; x < bw4; x++)
2148
19.3k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
19.6k
    for (int y = 0; y < bh4; y++)
2150
15.0k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
4.55k
}
2152
2153
void bytefn(dav1d_copy_pal_block_uv)(Dav1dTaskContext *const t,
2154
                                     const int bx4, const int by4,
2155
                                     const int bw4, const int bh4)
2156
2157
4.90k
{
2158
4.90k
    const Dav1dFrameContext *const f = t->f;
2159
4.90k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
4.90k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
4.90k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
4.90k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
14.7k
    for (int pl = 1; pl <= 2; pl++) {
2165
53.8k
        for (int x = 0; x < bw4; x++)
2166
44.0k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
49.2k
        for (int y = 0; y < bh4; y++)
2168
39.4k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
9.81k
    }
2170
4.90k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
2.28k
{
2158
2.28k
    const Dav1dFrameContext *const f = t->f;
2159
2.28k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
2.28k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
2.28k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
2.28k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
6.84k
    for (int pl = 1; pl <= 2; pl++) {
2165
24.4k
        for (int x = 0; x < bw4; x++)
2166
19.8k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
23.3k
        for (int y = 0; y < bh4; y++)
2168
18.7k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
4.56k
    }
2170
2.28k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
2.62k
{
2158
2.62k
    const Dav1dFrameContext *const f = t->f;
2159
2.62k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
2.62k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
2.62k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
2.62k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
7.87k
    for (int pl = 1; pl <= 2; pl++) {
2165
29.4k
        for (int x = 0; x < bw4; x++)
2166
24.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
25.9k
        for (int y = 0; y < bh4; y++)
2168
20.7k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
5.24k
    }
2170
2.62k
}
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
14.0k
{
2176
14.0k
    Dav1dTileState *const ts = t->ts;
2177
14.0k
    const Dav1dFrameContext *const f = t->f;
2178
14.0k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
14.0k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
14.0k
    pixel cache[16], used_cache[8];
2181
14.0k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
14.0k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
14.0k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
14.0k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
14.0k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
26.1k
    while (l_cache && a_cache) {
2190
12.0k
        if (*l < *a) {
2191
4.56k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
4.52k
                cache[n_cache++] = *l;
2193
4.56k
            l++;
2194
4.56k
            l_cache--;
2195
7.52k
        } else {
2196
7.52k
            if (*a == *l) {
2197
2.93k
                l++;
2198
2.93k
                l_cache--;
2199
2.93k
            }
2200
7.52k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
7.28k
                cache[n_cache++] = *a;
2202
7.52k
            a++;
2203
7.52k
            a_cache--;
2204
7.52k
        }
2205
12.0k
    }
2206
14.0k
    if (l_cache) {
2207
15.7k
        do {
2208
15.7k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
13.3k
                cache[n_cache++] = *l;
2210
15.7k
            l++;
2211
15.7k
        } while (--l_cache > 0);
2212
10.1k
    } else if (a_cache) {
2213
12.7k
        do {
2214
12.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
10.4k
                cache[n_cache++] = *a;
2216
12.7k
            a++;
2217
12.7k
        } while (--a_cache > 0);
2218
3.17k
    }
2219
2220
    // find reused cache entries
2221
14.0k
    int i = 0;
2222
45.3k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
31.2k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
15.8k
            used_cache[i++] = cache[n];
2225
14.0k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
14.0k
    pixel *const pal = t->frame_thread.pass ?
2229
14.0k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
14.0k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
14.0k
        bytefn(t->scratch.pal)[pl];
2232
14.0k
    if (i < pal_sz) {
2233
12.1k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
12.1k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
12.1k
        if (i < pal_sz) {
2237
10.8k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
10.8k
            const int max = (1 << bpc) - 1;
2239
2240
25.8k
            do {
2241
25.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
25.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
25.8k
                if (prev + !pl >= max) {
2244
13.0k
                    for (; i < pal_sz; i++)
2245
8.25k
                        pal[i] = max;
2246
4.82k
                    break;
2247
4.82k
                }
2248
21.0k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
21.0k
            } while (i < pal_sz);
2250
10.8k
        }
2251
2252
        // merge cache+new entries
2253
12.1k
        int n = 0, m = n_used_cache;
2254
68.9k
        for (i = 0; i < pal_sz; i++) {
2255
56.7k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
10.4k
                pal[i] = used_cache[n++];
2257
46.3k
            } else {
2258
46.3k
                assert(m < pal_sz);
2259
46.3k
                pal[i] = pal[m++];
2260
46.3k
            }
2261
56.7k
        }
2262
12.1k
    } else {
2263
1.94k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.94k
    }
2265
2266
14.0k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
14.0k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
6.91k
{
2176
6.91k
    Dav1dTileState *const ts = t->ts;
2177
6.91k
    const Dav1dFrameContext *const f = t->f;
2178
6.91k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
6.91k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
6.91k
    pixel cache[16], used_cache[8];
2181
6.91k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
6.91k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
6.91k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
6.91k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
6.91k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
13.2k
    while (l_cache && a_cache) {
2190
6.38k
        if (*l < *a) {
2191
2.45k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.42k
                cache[n_cache++] = *l;
2193
2.45k
            l++;
2194
2.45k
            l_cache--;
2195
3.93k
        } else {
2196
3.93k
            if (*a == *l) {
2197
1.51k
                l++;
2198
1.51k
                l_cache--;
2199
1.51k
            }
2200
3.93k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
3.81k
                cache[n_cache++] = *a;
2202
3.93k
            a++;
2203
3.93k
            a_cache--;
2204
3.93k
        }
2205
6.38k
    }
2206
6.91k
    if (l_cache) {
2207
7.42k
        do {
2208
7.42k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
6.18k
                cache[n_cache++] = *l;
2210
7.42k
            l++;
2211
7.42k
        } while (--l_cache > 0);
2212
5.05k
    } else if (a_cache) {
2213
6.44k
        do {
2214
6.44k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
5.18k
                cache[n_cache++] = *a;
2216
6.44k
            a++;
2217
6.44k
        } while (--a_cache > 0);
2218
1.61k
    }
2219
2220
    // find reused cache entries
2221
6.91k
    int i = 0;
2222
22.4k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
15.4k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
7.83k
            used_cache[i++] = cache[n];
2225
6.91k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
6.91k
    pixel *const pal = t->frame_thread.pass ?
2229
6.91k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
6.91k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
6.91k
        bytefn(t->scratch.pal)[pl];
2232
6.91k
    if (i < pal_sz) {
2233
5.98k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
5.98k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
5.98k
        if (i < pal_sz) {
2237
5.32k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
5.32k
            const int max = (1 << bpc) - 1;
2239
2240
12.6k
            do {
2241
12.6k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
12.6k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
12.6k
                if (prev + !pl >= max) {
2244
6.58k
                    for (; i < pal_sz; i++)
2245
4.09k
                        pal[i] = max;
2246
2.49k
                    break;
2247
2.49k
                }
2248
10.1k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
10.1k
            } while (i < pal_sz);
2250
5.32k
        }
2251
2252
        // merge cache+new entries
2253
5.98k
        int n = 0, m = n_used_cache;
2254
33.9k
        for (i = 0; i < pal_sz; i++) {
2255
27.9k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
5.21k
                pal[i] = used_cache[n++];
2257
22.7k
            } else {
2258
22.7k
                assert(m < pal_sz);
2259
22.7k
                pal[i] = pal[m++];
2260
22.7k
            }
2261
27.9k
        }
2262
5.98k
    } else {
2263
926
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
926
    }
2265
2266
6.91k
    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
6.91k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
7.17k
{
2176
7.17k
    Dav1dTileState *const ts = t->ts;
2177
7.17k
    const Dav1dFrameContext *const f = t->f;
2178
7.17k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
7.17k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
7.17k
    pixel cache[16], used_cache[8];
2181
7.17k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
7.17k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
7.17k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
7.17k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
7.17k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
12.8k
    while (l_cache && a_cache) {
2190
5.70k
        if (*l < *a) {
2191
2.11k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.09k
                cache[n_cache++] = *l;
2193
2.11k
            l++;
2194
2.11k
            l_cache--;
2195
3.59k
        } else {
2196
3.59k
            if (*a == *l) {
2197
1.41k
                l++;
2198
1.41k
                l_cache--;
2199
1.41k
            }
2200
3.59k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
3.46k
                cache[n_cache++] = *a;
2202
3.59k
            a++;
2203
3.59k
            a_cache--;
2204
3.59k
        }
2205
5.70k
    }
2206
7.17k
    if (l_cache) {
2207
8.37k
        do {
2208
8.37k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
7.15k
                cache[n_cache++] = *l;
2210
8.37k
            l++;
2211
8.37k
        } while (--l_cache > 0);
2212
5.10k
    } else if (a_cache) {
2213
6.34k
        do {
2214
6.34k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
5.22k
                cache[n_cache++] = *a;
2216
6.34k
            a++;
2217
6.34k
        } while (--a_cache > 0);
2218
1.55k
    }
2219
2220
    // find reused cache entries
2221
7.17k
    int i = 0;
2222
22.9k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
15.7k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
7.97k
            used_cache[i++] = cache[n];
2225
7.17k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
7.17k
    pixel *const pal = t->frame_thread.pass ?
2229
7.17k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
7.17k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
7.17k
        bytefn(t->scratch.pal)[pl];
2232
7.17k
    if (i < pal_sz) {
2233
6.16k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
6.16k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
6.16k
        if (i < pal_sz) {
2237
5.56k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
5.56k
            const int max = (1 << bpc) - 1;
2239
2240
13.2k
            do {
2241
13.2k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
13.2k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
13.2k
                if (prev + !pl >= max) {
2244
6.49k
                    for (; i < pal_sz; i++)
2245
4.16k
                        pal[i] = max;
2246
2.33k
                    break;
2247
2.33k
                }
2248
10.9k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
10.9k
            } while (i < pal_sz);
2250
5.56k
        }
2251
2252
        // merge cache+new entries
2253
6.16k
        int n = 0, m = n_used_cache;
2254
34.9k
        for (i = 0; i < pal_sz; i++) {
2255
28.8k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
5.24k
                pal[i] = used_cache[n++];
2257
23.5k
            } else {
2258
23.5k
                assert(m < pal_sz);
2259
23.5k
                pal[i] = pal[m++];
2260
23.5k
            }
2261
28.8k
        }
2262
6.16k
    } else {
2263
1.01k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.01k
    }
2265
2266
7.17k
    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.17k
}
2277
2278
void bytefn(dav1d_read_pal_uv)(Dav1dTaskContext *const t, Av1Block *const b,
2279
                               const int sz_ctx, const int bx4, const int by4)
2280
4.90k
{
2281
4.90k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
4.90k
    Dav1dTileState *const ts = t->ts;
2285
4.90k
    const Dav1dFrameContext *const f = t->f;
2286
4.90k
    pixel *const pal = t->frame_thread.pass ?
2287
4.90k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
4.90k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
4.90k
        bytefn(t->scratch.pal)[2];
2290
4.90k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
4.90k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.35k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.35k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.35k
        const int max = (1 << bpc) - 1;
2295
9.70k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
7.34k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
7.34k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
7.34k
            prev = pal[i] = (prev + delta) & max;
2299
7.34k
        }
2300
2.55k
    } else {
2301
13.1k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
10.5k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
2.55k
    }
2304
4.90k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
4.90k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
2.28k
{
2281
2.28k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
2.28k
    Dav1dTileState *const ts = t->ts;
2285
2.28k
    const Dav1dFrameContext *const f = t->f;
2286
2.28k
    pixel *const pal = t->frame_thread.pass ?
2287
2.28k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
2.28k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
2.28k
        bytefn(t->scratch.pal)[2];
2290
2.28k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
2.28k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.14k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.14k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.14k
        const int max = (1 << bpc) - 1;
2295
4.77k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
3.62k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
3.62k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
3.62k
            prev = pal[i] = (prev + delta) & max;
2299
3.62k
        }
2300
1.14k
    } else {
2301
5.91k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
4.77k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.13k
    }
2304
2.28k
    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.28k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
2.62k
{
2281
2.62k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
2.62k
    Dav1dTileState *const ts = t->ts;
2285
2.62k
    const Dav1dFrameContext *const f = t->f;
2286
2.62k
    pixel *const pal = t->frame_thread.pass ?
2287
2.62k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
2.62k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
2.62k
        bytefn(t->scratch.pal)[2];
2290
2.62k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
2.62k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.20k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.20k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.20k
        const int max = (1 << bpc) - 1;
2295
4.93k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
3.72k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
3.72k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
3.72k
            prev = pal[i] = (prev + delta) & max;
2299
3.72k
        }
2300
1.41k
    } else {
2301
7.23k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
5.82k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.41k
    }
2304
2.62k
    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.62k
}