Coverage Report

Created: 2026-08-13 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/recon_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018-2021, VideoLAN and dav1d authors
3
 * Copyright © 2018, Two Orioles, LLC
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright notice, this
10
 *    list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright notice,
13
 *    this list of conditions and the following disclaimer in the documentation
14
 *    and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
28
#include "config.h"
29
30
#include <string.h>
31
#include <stdio.h>
32
33
#include "common/attributes.h"
34
#include "common/bitdepth.h"
35
#include "common/dump.h"
36
#include "common/frame.h"
37
#include "common/intops.h"
38
39
#include "src/cdef_apply.h"
40
#include "src/ctx.h"
41
#include "src/ipred_prepare.h"
42
#include "src/lf_apply.h"
43
#include "src/lr_apply.h"
44
#include "src/recon.h"
45
#include "src/scan.h"
46
#include "src/tables.h"
47
#include "src/wedge.h"
48
49
479k
static inline unsigned read_golomb(MsacContext *const msac) {
50
479k
    int len = 0;
51
479k
    unsigned val = 1;
52
53
882k
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
882k
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
479k
    return val - 1;
57
479k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
3.04M
{
66
3.04M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
3.04M
    if (chroma) {
69
1.63M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
1.63M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
1.63M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
976k
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
1.63M
        unsigned ca, cl;
74
75
1.63M
#define MERGE_CTX(dir, type, no_val) \
76
3.27M
        c##dir = *(const type *) dir != no_val; \
77
3.27M
        break
78
79
1.63M
        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
685k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
279k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
257k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
412k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
1.63M
        }
91
1.63M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
751k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
315k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
200k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
367k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
1.63M
        }
98
1.63M
#undef MERGE_CTX
99
100
1.63M
        return 7 + not_one_blk * 3 + ca + cl;
101
1.63M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
547k
        return 0;
103
861k
    } else {
104
861k
        unsigned la, ll;
105
106
861k
#define MERGE_CTX(dir, type, tx) \
107
1.73M
        if (tx == TX_64X64) { \
108
75.7k
            uint64_t tmp = *(const uint64_t *) dir; \
109
75.7k
            tmp |= *(const uint64_t *) &dir[8]; \
110
75.7k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
75.7k
        } else \
112
1.73M
            l##dir = *(const type *) dir; \
113
1.73M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
1.73M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
1.73M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
1.73M
        break
117
118
861k
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
559k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
161k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
96.6k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
11.3k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
37.8k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
861k
        }
126
867k
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
563k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
158k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
96.4k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
11.2k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
37.8k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
867k
        }
134
867k
#undef MERGE_CTX
135
136
867k
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
867k
    }
138
3.04M
}
139
140
static inline unsigned get_dc_sign_ctx(const int /*enum RectTxfmSize*/ tx,
141
                                       const uint8_t *const a,
142
                                       const uint8_t *const l)
143
1.20M
{
144
1.20M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
1.20M
    int s;
146
147
1.20M
#if ARCH_X86_64 && defined(__GNUC__)
148
    /* Coerce compilers into producing better code. For some reason
149
     * every x86-64 compiler is awful at handling 64-bit constants. */
150
1.20M
    __asm__("" : "+r"(mask), "+r"(mul));
151
1.20M
#endif
152
153
1.20M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
518k
    case TX_4X4: {
156
518k
        int t = *(const uint8_t *) a >> 6;
157
518k
        t    += *(const uint8_t *) l >> 6;
158
518k
        s = t - 1 - 1;
159
518k
        break;
160
0
    }
161
127k
    case TX_8X8: {
162
127k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
127k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
127k
        t *= 0x04040404U;
165
127k
        s = (int) (t >> 24) - 2 - 2;
166
127k
        break;
167
0
    }
168
66.9k
    case TX_16X16: {
169
66.9k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
66.9k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
66.9k
        t *= (uint32_t) mul;
172
66.9k
        s = (int) (t >> 24) - 4 - 4;
173
66.9k
        break;
174
0
    }
175
89.9k
    case TX_32X32: {
176
89.9k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
89.9k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
89.9k
        t *= mul;
179
89.9k
        s = (int) (t >> 56) - 8 - 8;
180
89.9k
        break;
181
0
    }
182
23.9k
    case TX_64X64: {
183
23.9k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
23.9k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
23.9k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
23.9k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
23.9k
        t *= mul;
188
23.9k
        s = (int) (t >> 56) - 16 - 16;
189
23.9k
        break;
190
0
    }
191
40.2k
    case RTX_4X8: {
192
40.2k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
40.2k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
40.2k
        t *= 0x04040404U;
195
40.2k
        s = (int) (t >> 24) - 1 - 2;
196
40.2k
        break;
197
0
    }
198
64.9k
    case RTX_8X4: {
199
64.9k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
64.9k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
64.9k
        t *= 0x04040404U;
202
64.9k
        s = (int) (t >> 24) - 2 - 1;
203
64.9k
        break;
204
0
    }
205
32.1k
    case RTX_8X16: {
206
32.1k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
32.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
32.1k
        t = (t >> 6) * (uint32_t) mul;
209
32.1k
        s = (int) (t >> 24) - 2 - 4;
210
32.1k
        break;
211
0
    }
212
76.7k
    case RTX_16X8: {
213
76.7k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
76.7k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
76.7k
        t = (t >> 6) * (uint32_t) mul;
216
76.7k
        s = (int) (t >> 24) - 4 - 2;
217
76.7k
        break;
218
0
    }
219
19.9k
    case RTX_16X32: {
220
19.9k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
19.9k
        t         += *(const uint64_t *) l & mask;
222
19.9k
        t = (t >> 6) * mul;
223
19.9k
        s = (int) (t >> 56) - 4 - 8;
224
19.9k
        break;
225
0
    }
226
46.1k
    case RTX_32X16: {
227
46.1k
        uint64_t t = *(const uint64_t *) a & mask;
228
46.1k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
46.1k
        t = (t >> 6) * mul;
230
46.1k
        s = (int) (t >> 56) - 8 - 4;
231
46.1k
        break;
232
0
    }
233
21.0k
    case RTX_32X64: {
234
21.0k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
21.0k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
21.0k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
21.0k
        t *= mul;
238
21.0k
        s = (int) (t >> 56) - 8 - 16;
239
21.0k
        break;
240
0
    }
241
17.4k
    case RTX_64X32: {
242
17.4k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
17.4k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
17.4k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
17.4k
        t *= mul;
246
17.4k
        s = (int) (t >> 56) - 16 - 8;
247
17.4k
        break;
248
0
    }
249
14.7k
    case RTX_4X16: {
250
14.7k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
14.7k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
14.7k
        t = (t >> 6) * (uint32_t) mul;
253
14.7k
        s = (int) (t >> 24) - 1 - 4;
254
14.7k
        break;
255
0
    }
256
25.1k
    case RTX_16X4: {
257
25.1k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
25.1k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
25.1k
        t = (t >> 6) * (uint32_t) mul;
260
25.1k
        s = (int) (t >> 24) - 4 - 1;
261
25.1k
        break;
262
0
    }
263
7.26k
    case RTX_8X32: {
264
7.26k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
7.26k
        t         += *(const uint64_t *) l & mask;
266
7.26k
        t = (t >> 6) * mul;
267
7.26k
        s = (int) (t >> 56) - 2 - 8;
268
7.26k
        break;
269
0
    }
270
10.4k
    case RTX_32X8: {
271
10.4k
        uint64_t t = *(const uint64_t *) a & mask;
272
10.4k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
10.4k
        t = (t >> 6) * mul;
274
10.4k
        s = (int) (t >> 56) - 8 - 2;
275
10.4k
        break;
276
0
    }
277
1.81k
    case RTX_16X64: {
278
1.81k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
1.81k
        t         += *(const uint64_t *) &l[0] & mask;
280
1.81k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
1.81k
        t *= mul;
282
1.81k
        s = (int) (t >> 56) - 4 - 16;
283
1.81k
        break;
284
0
    }
285
1.66k
    case RTX_64X16: {
286
1.66k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
1.66k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
1.66k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
1.66k
        t *= mul;
290
1.66k
        s = (int) (t >> 56) - 16 - 4;
291
1.66k
        break;
292
0
    }
293
1.20M
    }
294
295
1.20M
    return (s != 0) + (s > 0);
296
1.20M
}
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
23.7M
{
305
23.7M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
23.7M
    unsigned offset;
307
23.7M
    if (tx_class == TX_CLASS_2D) {
308
21.7M
        mag += levels[1 * stride + 1];
309
21.7M
        *hi_mag = mag;
310
21.7M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
21.7M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
21.7M
    } else {
313
1.95M
        mag += levels[0 * stride + 2];
314
1.95M
        *hi_mag = mag;
315
1.95M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
1.95M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
1.95M
    }
318
23.7M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
23.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
3.04M
{
328
3.04M
    Dav1dTileState *const ts = t->ts;
329
3.04M
    const int chroma = !!plane;
330
3.04M
    const Dav1dFrameContext *const f = t->f;
331
3.04M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
3.04M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
3.04M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
3.04M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
3.04M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
3.04M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
3.04M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
3.04M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
3.04M
    if (all_skip) {
346
1.57M
        *res_ctx = 0x40;
347
1.57M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
1.57M
        return -1;
349
1.57M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
1.46M
    if (lossless) {
353
482k
        assert(t_dim->max == TX_4X4);
354
482k
        *txtp = WHT_WHT;
355
983k
    } else if (t_dim->max + intra >= TX_64X64) {
356
216k
        *txtp = DCT_DCT;
357
767k
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
183k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
183k
                        get_uv_inter_txtp(t_dim, *txtp);
361
584k
    } 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
14.6k
        *txtp = DCT_DCT;
366
569k
    } else {
367
569k
        unsigned idx;
368
569k
        if (intra) {
369
293k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
263k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
293k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
94.6k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
94.6k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
94.6k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
198k
            } else {
376
198k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
198k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
198k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
198k
            }
380
293k
            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
293k
        } else {
384
276k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
81.5k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
81.5k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
81.5k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
194k
            } else if (t_dim->min == TX_16X16) {
389
21.0k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
21.0k
                          ts->cdf.m.txtp_inter2, 11);
391
21.0k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
173k
            } else {
393
173k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
173k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
173k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
173k
            }
397
276k
            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
276k
        }
401
569k
    }
402
403
    // find end-of-block (eob)
404
1.46M
    int eob;
405
1.46M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
1.46M
    const int tx2dszctx = slw + slh;
407
1.46M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
1.46M
    const int is_1d = tx_class != TX_CLASS_2D;
409
1.46M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
1.47M
    case sz: { \
412
1.47M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
1.47M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
1.47M
        break; \
415
1.47M
    }
416
617k
    case_sz(0,   16,  8, [is_1d]);
417
141k
    case_sz(1,   32,  8, [is_1d]);
418
218k
    case_sz(2,   64,  8, [is_1d]);
419
145k
    case_sz(3,  128,  8, [is_1d]);
420
105k
    case_sz(4,  256, 16, [is_1d]);
421
80.2k
    case_sz(5,  512, 16,        );
422
161k
    case_sz(6, 1024, 16,        );
423
1.46M
#undef case_sz
424
1.46M
    }
425
1.46M
    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.46M
    if (eob > 1) {
429
1.02M
        const int eob_bin = eob - 2;
430
1.02M
        uint16_t *const eob_hi_bit_cdf =
431
1.02M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.02M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.02M
        if (dbg)
434
0
            printf("Post-eob_hi_bit[%d][%d][%d][%d]: r=%d\n",
435
0
                   t_dim->ctx, chroma, eob_bin, eob_hi_bit, ts->msac.rng);
436
1.02M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.02M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.02M
    }
440
1.46M
    assert(eob >= 0);
441
442
    // base tokens
443
1.46M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
1.46M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
1.46M
    unsigned rc, dc_tok;
446
447
1.46M
    if (eob) {
448
1.08M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.08M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.08M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.08M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.08M
        int tok = eob_tok + 1;
455
1.08M
        int level_tok = tok * 0x41;
456
1.08M
        unsigned mag;
457
458
1.08M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.08M
        unsigned x, y; \
460
1.08M
        uint8_t *level; \
461
1.08M
        if (tx_class == TX_CLASS_2D) \
462
1.08M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.08M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
113k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
113k
        else /* tx_class == TX_CLASS_V */ \
467
113k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.08M
        if (dbg) \
469
1.08M
            printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
470
0
                   t_dim->ctx, chroma, ctx, eob, rc, tok, ts->msac.rng); \
471
1.08M
        if (eob_tok == 2) { \
472
36.0k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
36.0k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
36.0k
            level_tok = tok + (3 << 6); \
475
36.0k
            if (dbg) \
476
36.0k
                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
36.0k
        } \
480
1.08M
        cf[rc] = tok << 11; \
481
1.08M
        if (tx_class == TX_CLASS_2D) \
482
1.08M
            level = levels + rc; \
483
1.08M
        else \
484
1.08M
            level = levels + x * stride + y; \
485
1.08M
        *level = (uint8_t) level_tok; \
486
24.7M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
23.6M
            unsigned rc_i; \
488
23.6M
            if (tx_class == TX_CLASS_2D) \
489
23.6M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
23.6M
            else if (tx_class == TX_CLASS_H) \
491
1.90M
                x = i & mask, y = i >> shift, rc_i = i; \
492
1.90M
            else /* tx_class == TX_CLASS_V */ \
493
1.90M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
23.6M
            assert(x < 32 && y < 32); \
495
23.6M
            if (tx_class == TX_CLASS_2D) \
496
23.6M
                level = levels + rc_i; \
497
23.6M
            else \
498
23.6M
                level = levels + x * stride + y; \
499
23.6M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
23.6M
            if (tx_class == TX_CLASS_2D) \
501
23.6M
                y |= x; \
502
23.6M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
23.6M
            if (dbg) \
504
23.6M
                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
23.6M
            if (tok == 3) { \
507
2.15M
                mag &= 63; \
508
2.15M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
2.15M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
2.15M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
2.15M
                if (dbg) \
512
2.15M
                    printf("Post-hi_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
513
0
                           imin(t_dim->ctx, 3), chroma, ctx, i, rc_i, tok, \
514
0
                           ts->msac.rng); \
515
2.15M
                *level = (uint8_t) (tok + (3 << 6)); \
516
2.15M
                cf[rc_i] = (tok << 11) | rc; \
517
2.15M
                rc = rc_i; \
518
21.4M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
21.4M
                tok *= 0x17ff41; \
521
21.4M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
21.4M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
21.4M
                if (tok) rc = rc_i; \
525
21.4M
                cf[rc_i] = tok; \
526
21.4M
            } \
527
23.6M
        } \
528
        /* dc */ \
529
1.08M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.08M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.08M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.08M
        if (dbg) \
533
1.08M
            printf("Post-dc_lo_tok[%d][%d][%d][%d]: r=%d\n", \
534
0
                   t_dim->ctx, chroma, ctx, dc_tok, ts->msac.rng); \
535
1.08M
        if (dc_tok == 3) { \
536
412k
            if (tx_class == TX_CLASS_2D) \
537
412k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
400k
                      levels[1 * stride + 1]; \
539
412k
            mag &= 63; \
540
412k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
412k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
412k
            if (dbg) \
543
412k
                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
412k
        } \
546
1.08M
        break
547
548
1.08M
        const uint16_t *scan;
549
1.08M
        switch (tx_class) {
550
972k
        case TX_CLASS_2D: {
551
972k
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
972k
            const uint8_t (*const lo_ctx_offsets)[5] =
553
972k
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
972k
            scan = dav1d_scans[tx];
555
972k
            const ptrdiff_t stride = 4 << slh;
556
972k
            const unsigned shift = slh + 2, shift2 = 0;
557
972k
            const unsigned mask = (4 << slh) - 1;
558
972k
            memset(levels, 0, stride * ((4 << slw) + 2));
559
972k
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
972k
        }
561
68.3k
        case TX_CLASS_H: {
562
68.3k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
68.3k
            const ptrdiff_t stride = 16;
564
68.3k
            const unsigned shift = slh + 2, shift2 = 0;
565
68.3k
            const unsigned mask = (4 << slh) - 1;
566
68.3k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
68.3k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
68.3k
        }
569
44.7k
        case TX_CLASS_V: {
570
44.7k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
44.7k
            const ptrdiff_t stride = 16;
572
44.7k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
44.7k
            const unsigned mask = (4 << slw) - 1;
574
44.7k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
44.7k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
44.7k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.08M
        }
580
1.08M
    } else { // dc-only
581
381k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
381k
        dc_tok = 1 + tok_br;
583
381k
        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
381k
        if (tok_br == 2) {
587
17.7k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
17.7k
            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
17.7k
        }
592
381k
        rc = 0;
593
381k
    }
594
595
    // residual and sign
596
1.46M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
1.46M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
1.46M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
1.46M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
1.46M
    unsigned cul_level, dc_sign_level;
601
602
1.46M
    if (!dc_tok) {
603
263k
        cul_level = 0;
604
263k
        dc_sign_level = 1 << 6;
605
263k
        if (qm_tbl) goto ac_qm;
606
203k
        goto ac_noqm;
607
263k
    }
608
609
1.20M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
1.20M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
1.20M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
1.20M
    if (dbg)
613
0
        printf("Post-dc_sign[%d][%d][%d]: r=%d\n",
614
0
               chroma, dc_sign_ctx, dc_sign, ts->msac.rng);
615
616
1.20M
    int dc_dq = dq_tbl[0];
617
1.20M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
1.20M
    if (qm_tbl) {
620
305k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
305k
        if (dc_tok == 15) {
623
12.7k
            dc_tok = read_golomb(&ts->msac) + 15;
624
12.7k
            if (dbg)
625
0
                printf("Post-dc_residual[%d->%d]: r=%d\n",
626
0
                       dc_tok - 15, dc_tok, ts->msac.rng);
627
628
12.7k
            dc_tok &= 0xfffff;
629
12.7k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
293k
        } else {
631
293k
            dc_dq *= dc_tok;
632
293k
            assert(dc_dq <= 0xffffff);
633
293k
        }
634
305k
        cul_level = dc_tok;
635
305k
        dc_dq >>= dq_shift;
636
305k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
305k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
471k
        if (rc) ac_qm: {
640
471k
            const unsigned ac_dq = dq_tbl[1];
641
3.39M
            do {
642
3.39M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
3.39M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
3.39M
                const unsigned rc_tok = cf[rc];
646
3.39M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
3.39M
                int dq_sat;
648
649
3.39M
                if (rc_tok >= (15 << 11)) {
650
296k
                    tok = read_golomb(&ts->msac) + 15;
651
296k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
296k
                    tok &= 0xfffff;
656
296k
                    dq = (dq * tok) & 0xffffff;
657
3.09M
                } else {
658
3.09M
                    tok = rc_tok >> 11;
659
3.09M
                    dq *= tok;
660
3.09M
                    assert(dq <= 0xffffff);
661
3.09M
                }
662
3.39M
                cul_level += tok;
663
3.39M
                dq >>= dq_shift;
664
3.39M
                dq_sat = umin(dq, cf_max + sign);
665
3.39M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
3.39M
                rc = rc_tok & 0x3ff;
668
3.39M
            } while (rc);
669
471k
        }
670
896k
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
896k
        if (dc_tok == 15) {
673
40.4k
            dc_tok = read_golomb(&ts->msac) + 15;
674
40.4k
            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
40.4k
            dc_tok &= 0xfffff;
679
40.4k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
40.4k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
856k
        } else {
682
856k
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
856k
            assert(dc_dq <= cf_max);
684
856k
        }
685
896k
        cul_level = dc_tok;
686
896k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
1.43M
        if (rc) ac_noqm: {
689
1.43M
            const unsigned ac_dq = dq_tbl[1];
690
6.46M
            do {
691
6.46M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
6.46M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
6.46M
                const unsigned rc_tok = cf[rc];
695
6.46M
                unsigned tok;
696
6.46M
                int dq;
697
698
                // residual
699
6.46M
                if (rc_tok >= (15 << 11)) {
700
129k
                    tok = read_golomb(&ts->msac) + 15;
701
129k
                    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
129k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
129k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
129k
                    dq = umin(dq, cf_max + sign);
711
6.33M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
6.33M
                    tok = rc_tok >> 11;
714
6.33M
                    dq = ((ac_dq * tok) >> dq_shift);
715
6.33M
                    assert(dq <= cf_max);
716
6.33M
                }
717
6.46M
                cul_level += tok;
718
6.46M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
6.46M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
6.46M
            } while (rc);
722
1.43M
        }
723
896k
    }
724
725
    // context
726
1.46M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
1.46M
    return eob;
729
1.20M
}
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
854k
{
737
854k
    const Dav1dFrameContext *const f = t->f;
738
854k
    Dav1dTileState *const ts = t->ts;
739
854k
    const Dav1dDSPContext *const dsp = f->dsp;
740
854k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
854k
    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
854k
    if (depth < 2 && tx_split[depth] &&
746
98.9k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
81.1k
    {
748
81.1k
        const enum RectTxfmSize sub = t_dim->sub;
749
81.1k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
81.1k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
81.1k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
81.1k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
81.1k
        t->bx += txsw;
755
81.1k
        if (txw >= txh && t->bx < f->bw)
756
63.2k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
63.2k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
81.1k
        t->bx -= txsw;
759
81.1k
        t->by += txsh;
760
81.1k
        if (txh >= txw && t->by < f->bh) {
761
50.0k
            if (dst)
762
18.0k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
50.0k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
50.0k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
50.0k
            t->bx += txsw;
766
50.0k
            if (txw >= txh && t->bx < f->bw)
767
33.3k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
33.3k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
50.0k
            t->bx -= txsw;
770
50.0k
        }
771
81.1k
        t->by -= txsh;
772
773k
    } else {
773
773k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
773k
        enum TxfmType txtp;
775
773k
        uint8_t cf_ctx;
776
773k
        int eob;
777
773k
        coef *cf;
778
779
773k
        if (t->frame_thread.pass) {
780
773k
            const int p = t->frame_thread.pass & 1;
781
773k
            assert(ts->frame_thread[p].cf);
782
773k
            cf = ts->frame_thread[p].cf;
783
773k
            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
773k
        if (t->frame_thread.pass != 2) {
788
514k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
514k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
514k
            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
514k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
514k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
514k
#define set_ctx(rep_macro) \
796
1.93M
            for (int y = 0; y < txh; y++) { \
797
1.42M
                rep_macro(txtp_map, 0, txtp); \
798
1.42M
                txtp_map += 32; \
799
1.42M
            }
800
514k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
514k
            case_set_upto16(t_dim->lw);
802
514k
#undef set_ctx
803
514k
            if (t->frame_thread.pass == 1)
804
514k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
514k
        } else {
806
258k
            const int cbi = *ts->frame_thread[0].cbi++;
807
258k
            eob  = cbi >> 5;
808
258k
            txtp = cbi & 0x1f;
809
258k
        }
810
773k
        if (!(t->frame_thread.pass & 1)) {
811
258k
            assert(dst);
812
258k
            if (eob >= 0) {
813
191k
                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
191k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
191k
                                              HIGHBD_CALL_SUFFIX);
817
191k
                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
191k
            }
820
258k
        }
821
773k
    }
822
854k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
1.60M
{
827
1.60M
    const Dav1dFrameContext *const f = t->f;
828
1.60M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.60M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.60M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.60M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.60M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.60M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.60M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.60M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.29M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.17M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.60M
    if (b->skip) {
840
923k
        BlockContext *const a = t->a;
841
923k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
923k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
923k
        if (has_chroma) {
844
588k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
588k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
588k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
588k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
588k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
588k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
588k
        }
851
923k
        return;
852
923k
    }
853
854
678k
    Dav1dTileState *const ts = t->ts;
855
678k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
678k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
678k
    assert(t->frame_thread.pass == 1);
858
678k
    assert(!b->skip);
859
678k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
678k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
678k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.37M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
692k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.39M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
704k
            const int sub_w4 = imin(w4, init_x + 16);
867
704k
            int y_off = !!init_y, y, x;
868
1.51M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
809k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
809k
            {
871
809k
                int x_off = !!init_x;
872
2.13M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.32M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.32M
                {
875
1.32M
                    if (!b->intra) {
876
420k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
420k
                                       x_off, y_off, NULL);
878
900k
                    } else {
879
900k
                        uint8_t cf_ctx = 0x40;
880
900k
                        enum TxfmType txtp;
881
900k
                        const int eob =
882
900k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
900k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
900k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
900k
                        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
900k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
900k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
900k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
900k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
900k
                    }
893
1.32M
                }
894
809k
                t->bx -= x;
895
809k
            }
896
704k
            t->by -= y;
897
898
704k
            if (!has_chroma) continue;
899
900
534k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
534k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.60M
            for (int pl = 0; pl < 2; pl++) {
903
2.26M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.19M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.19M
                {
906
2.82M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.63M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.63M
                    {
909
1.63M
                        uint8_t cf_ctx = 0x40;
910
1.63M
                        enum TxfmType txtp;
911
1.63M
                        if (!b->intra)
912
449k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
449k
                                                        bx4 + (x << ss_hor)];
914
1.63M
                        const int eob =
915
1.63M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.63M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.63M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.63M
                                         &txtp, &cf_ctx);
919
1.63M
                        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.63M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.63M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.63M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.63M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.63M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.63M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.63M
                    }
930
1.19M
                    t->bx -= x << ss_hor;
931
1.19M
                }
932
1.06M
                t->by -= y << ss_ver;
933
1.06M
            }
934
534k
        }
935
692k
    }
936
678k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
782k
{
827
782k
    const Dav1dFrameContext *const f = t->f;
828
782k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
782k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
782k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
782k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
782k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
782k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
782k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
782k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
660k
                           (bw4 > ss_hor || t->bx & 1) &&
837
604k
                           (bh4 > ss_ver || t->by & 1);
838
839
782k
    if (b->skip) {
840
449k
        BlockContext *const a = t->a;
841
449k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
449k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
449k
        if (has_chroma) {
844
309k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
309k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
309k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
309k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
309k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
309k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
309k
        }
851
449k
        return;
852
449k
    }
853
854
332k
    Dav1dTileState *const ts = t->ts;
855
332k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
332k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
332k
    assert(t->frame_thread.pass == 1);
858
332k
    assert(!b->skip);
859
332k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
332k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
332k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
672k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
339k
        const int sub_h4 = imin(h4, 16 + init_y);
865
684k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
345k
            const int sub_w4 = imin(w4, init_x + 16);
867
345k
            int y_off = !!init_y, y, x;
868
738k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
393k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
393k
            {
871
393k
                int x_off = !!init_x;
872
1.02M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
630k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
630k
                {
875
630k
                    if (!b->intra) {
876
179k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
179k
                                       x_off, y_off, NULL);
878
450k
                    } else {
879
450k
                        uint8_t cf_ctx = 0x40;
880
450k
                        enum TxfmType txtp;
881
450k
                        const int eob =
882
450k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
450k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
450k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
450k
                        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
450k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
450k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
450k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
450k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
450k
                    }
893
630k
                }
894
393k
                t->bx -= x;
895
393k
            }
896
345k
            t->by -= y;
897
898
345k
            if (!has_chroma) continue;
899
900
270k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
270k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
811k
            for (int pl = 0; pl < 2; pl++) {
903
1.13M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
597k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
597k
                {
906
1.39M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
799k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
799k
                    {
909
799k
                        uint8_t cf_ctx = 0x40;
910
799k
                        enum TxfmType txtp;
911
799k
                        if (!b->intra)
912
211k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
211k
                                                        bx4 + (x << ss_hor)];
914
799k
                        const int eob =
915
799k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
799k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
799k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
799k
                                         &txtp, &cf_ctx);
919
799k
                        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
799k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
799k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
799k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
799k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
799k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
799k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
799k
                    }
930
597k
                    t->bx -= x << ss_hor;
931
597k
                }
932
541k
                t->by -= y << ss_ver;
933
541k
            }
934
270k
        }
935
339k
    }
936
332k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
819k
{
827
819k
    const Dav1dFrameContext *const f = t->f;
828
819k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
819k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
819k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
819k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
819k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
819k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
819k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
819k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
631k
                           (bw4 > ss_hor || t->bx & 1) &&
837
571k
                           (bh4 > ss_ver || t->by & 1);
838
839
819k
    if (b->skip) {
840
474k
        BlockContext *const a = t->a;
841
474k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
474k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
474k
        if (has_chroma) {
844
278k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
278k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
278k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
278k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
278k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
278k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
278k
        }
851
474k
        return;
852
474k
    }
853
854
345k
    Dav1dTileState *const ts = t->ts;
855
345k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
345k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
345k
    assert(t->frame_thread.pass == 1);
858
345k
    assert(!b->skip);
859
345k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
345k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
345k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
698k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
353k
        const int sub_h4 = imin(h4, 16 + init_y);
865
712k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
359k
            const int sub_w4 = imin(w4, init_x + 16);
867
359k
            int y_off = !!init_y, y, x;
868
775k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
416k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
416k
            {
871
416k
                int x_off = !!init_x;
872
1.10M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
690k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
690k
                {
875
690k
                    if (!b->intra) {
876
240k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
240k
                                       x_off, y_off, NULL);
878
449k
                    } else {
879
449k
                        uint8_t cf_ctx = 0x40;
880
449k
                        enum TxfmType txtp;
881
449k
                        const int eob =
882
449k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
449k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
449k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
449k
                        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
449k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
449k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
449k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
449k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
449k
                    }
893
690k
                }
894
416k
                t->bx -= x;
895
416k
            }
896
359k
            t->by -= y;
897
898
359k
            if (!has_chroma) continue;
899
900
264k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
264k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
792k
            for (int pl = 0; pl < 2; pl++) {
903
1.12M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
597k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
597k
                {
906
1.43M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
835k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
835k
                    {
909
835k
                        uint8_t cf_ctx = 0x40;
910
835k
                        enum TxfmType txtp;
911
835k
                        if (!b->intra)
912
237k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
237k
                                                        bx4 + (x << ss_hor)];
914
835k
                        const int eob =
915
835k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
835k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
835k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
835k
                                         &txtp, &cf_ctx);
919
835k
                        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
835k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
835k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
835k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
835k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
835k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
835k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
835k
                    }
930
597k
                    t->bx -= x << ss_hor;
931
597k
                }
932
528k
                t->by -= y << ss_ver;
933
528k
            }
934
264k
        }
935
353k
    }
936
345k
}
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
860k
{
945
860k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
860k
    const Dav1dFrameContext *const f = t->f;
947
860k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
860k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
860k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
860k
    const int mvx = mv.x, mvy = mv.y;
951
860k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
860k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
860k
    const pixel *ref;
954
955
860k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
555k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
555k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
555k
        int w, h;
959
960
555k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
436k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
436k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
436k
        } else {
964
118k
            w = f->bw * 4 >> ss_hor;
965
118k
            h = f->bh * 4 >> ss_ver;
966
118k
        }
967
555k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
371k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
194k
            dy + bh4 * v_mul + !!my * 4 > h)
970
402k
        {
971
402k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
402k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
402k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
402k
                                emu_edge_buf, 192 * sizeof(pixel),
975
402k
                                refp->p.data[pl], ref_stride);
976
402k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
402k
            ref_stride = 192 * sizeof(pixel);
978
402k
        } else {
979
152k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
152k
        }
981
982
555k
        if (dst8 != NULL) {
983
438k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
438k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
438k
                                     HIGHBD_CALL_SUFFIX);
986
438k
        } else {
987
116k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
116k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
116k
                                      HIGHBD_CALL_SUFFIX);
990
116k
        }
991
555k
    } else {
992
304k
        assert(refp != &f->sr_cur);
993
994
304k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
304k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
609k
#define scale_mv(res, val, scale) do { \
997
609k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
609k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
609k
        } while (0)
1000
304k
        int pos_y, pos_x;
1001
304k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
304k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
304k
#undef scale_mv
1004
304k
        const int left = pos_x >> 10;
1005
304k
        const int top = pos_y >> 10;
1006
304k
        const int right =
1007
304k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
304k
        const int bottom =
1009
304k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
304k
        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
304k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
304k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
304k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
237k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
237k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
237k
                                w, h, left - 3, top - 3,
1023
237k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
237k
                                refp->p.data[pl], ref_stride);
1025
237k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
237k
            ref_stride = 320 * sizeof(pixel);
1027
237k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
237k
        } else {
1029
67.7k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
67.7k
        }
1031
1032
304k
        if (dst8 != NULL) {
1033
238k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
238k
                                            bw4 * h_mul, bh4 * v_mul,
1035
238k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
238k
                                            f->svc[refidx][0].step,
1037
238k
                                            f->svc[refidx][1].step
1038
238k
                                            HIGHBD_CALL_SUFFIX);
1039
238k
        } else {
1040
66.5k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
66.5k
                                             bw4 * h_mul, bh4 * v_mul,
1042
66.5k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
66.5k
                                             f->svc[refidx][0].step,
1044
66.5k
                                             f->svc[refidx][1].step
1045
66.5k
                                             HIGHBD_CALL_SUFFIX);
1046
66.5k
        }
1047
304k
    }
1048
1049
860k
    return 0;
1050
860k
}
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
60.9k
{
1057
60.9k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
60.9k
    const Dav1dFrameContext *const f = t->f;
1059
60.9k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
60.9k
    pixel *const lap = bitfn(t->scratch.lap);
1061
60.9k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
60.9k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
60.9k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
60.9k
    int res;
1065
1066
60.9k
    if (t->by > t->ts->tiling.row_start &&
1067
46.4k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
41.0k
    {
1069
86.8k
        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
45.7k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
45.7k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
45.7k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
45.7k
            if (a_r->ref.ref[0] > 0) {
1076
45.0k
                const int ow4 = imin(step4, b_dim[0]);
1077
45.0k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
45.0k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
45.0k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
45.0k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
45.0k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
45.0k
                if (res) return res;
1083
45.0k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
45.0k
                                   h_mul * ow4, v_mul * oh4);
1085
45.0k
                i++;
1086
45.0k
            }
1087
45.7k
            x += step4;
1088
45.7k
        }
1089
41.0k
    }
1090
1091
60.9k
    if (t->bx > t->ts->tiling.col_start)
1092
105k
        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
54.9k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
54.9k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
54.9k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
54.9k
            if (l_r->ref.ref[0] > 0) {
1099
54.0k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
54.0k
                const int oh4 = imin(step4, b_dim[1]);
1101
54.0k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
54.0k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
54.0k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
54.0k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
54.0k
                if (res) return res;
1106
54.0k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
54.0k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
54.0k
                i++;
1109
54.0k
            }
1110
54.9k
            y += step4;
1111
54.9k
        }
1112
60.9k
    return 0;
1113
60.9k
}
1114
1115
static int warp_affine(Dav1dTaskContext *const t,
1116
                       pixel *dst8, int16_t *dst16, const ptrdiff_t dstride,
1117
                       const uint8_t *const b_dim, const int pl,
1118
                       const Dav1dThreadPicture *const refp,
1119
                       const Dav1dWarpedMotionParams *const wmp)
1120
17.4k
{
1121
17.4k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
17.4k
    const Dav1dFrameContext *const f = t->f;
1123
17.4k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
17.4k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
17.4k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
17.4k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
17.4k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
17.4k
    const int32_t *const mat = wmp->matrix;
1129
17.4k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
17.4k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
62.5k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
45.1k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
45.1k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
45.1k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
165k
        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
119k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
119k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
119k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
119k
            const int dx = (int) (mvx >> 16) - 4;
1144
119k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
119k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
119k
            const int dy = (int) (mvy >> 16) - 4;
1147
119k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
119k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
119k
            const pixel *ref_ptr;
1151
119k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
119k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
96.5k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
96.5k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
96.5k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
96.5k
                                    refp->p.data[pl], ref_stride);
1158
96.5k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
96.5k
                ref_stride = 32 * sizeof(pixel);
1160
96.5k
            } else {
1161
23.3k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
23.3k
            }
1163
119k
            if (dst16 != NULL)
1164
39.7k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
39.7k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
80.1k
            else
1167
80.1k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
80.1k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
119k
        }
1170
45.1k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
13.6k
        else      dst16 += 8 * dstride;
1172
45.1k
    }
1173
17.4k
    return 0;
1174
17.4k
}
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
336k
{
1180
336k
    Dav1dTileState *const ts = t->ts;
1181
336k
    const Dav1dFrameContext *const f = t->f;
1182
336k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
336k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
336k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
336k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
336k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
336k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
336k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
336k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
336k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
336k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
282k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
273k
                           (bh4 > ss_ver || t->by & 1);
1194
336k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
336k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
336k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
336k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
336k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
685k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
348k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
348k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
708k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
358k
            if (b->pal_sz[0]) {
1208
4.32k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
4.32k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
4.32k
                const uint8_t *pal_idx;
1211
4.32k
                if (t->frame_thread.pass) {
1212
4.32k
                    const int p = t->frame_thread.pass & 1;
1213
4.32k
                    assert(ts->frame_thread[p].pal_idx);
1214
4.32k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
4.32k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
4.32k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
4.32k
                const pixel *const pal = t->frame_thread.pass ?
1220
4.32k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
4.32k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
4.32k
                    bytefn(t->scratch.pal)[0];
1223
4.32k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
4.32k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
4.32k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1226
0
                    hex_dump(dst, PXSTRIDE(f->cur.stride[0]),
1227
0
                             bw4 * 4, bh4 * 4, "y-pal-pred");
1228
4.32k
            }
1229
1230
358k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
358k
                                     sm_flag(&t->l, by4) |
1232
358k
                                     intra_edge_filter_flag);
1233
358k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
348k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
358k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
348k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
358k
            int y, x;
1238
358k
            const int sub_w4 = imin(w4, init_x + 16);
1239
847k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
489k
                 y += t_dim->h, t->by += t_dim->h)
1241
488k
            {
1242
488k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
488k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
488k
                                    t->bx + init_x);
1245
1.50M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.01M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.01M
                {
1248
1.01M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.01M
                    int angle = b->y_angle;
1251
1.01M
                    const enum EdgeFlags edge_flags =
1252
1.01M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
817k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.01M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
698k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.01M
                    const pixel *top_sb_edge = NULL;
1257
1.01M
                    if (!(t->by & (f->sb_step - 1))) {
1258
240k
                        top_sb_edge = f->ipred_edge[0];
1259
240k
                        const int sby = t->by >> f->sb_shift;
1260
240k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
240k
                    }
1262
1.01M
                    const enum IntraPredMode m =
1263
1.01M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.01M
                                                          t->bx > ts->tiling.col_start,
1265
1.01M
                                                          t->by,
1266
1.01M
                                                          t->by > ts->tiling.row_start,
1267
1.01M
                                                          ts->tiling.col_end,
1268
1.01M
                                                          ts->tiling.row_end,
1269
1.01M
                                                          edge_flags, dst,
1270
1.01M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.01M
                                                          b->y_mode, &angle,
1272
1.01M
                                                          t_dim->w, t_dim->h,
1273
1.01M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.01M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.01M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.01M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.01M
                                             angle | intra_flags,
1278
1.01M
                                             4 * f->bw - 4 * t->bx,
1279
1.01M
                                             4 * f->bh - 4 * t->by
1280
1.01M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.01M
                    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.01M
                skip_y_pred: {}
1293
1.01M
                    if (!b->skip) {
1294
252k
                        coef *cf;
1295
252k
                        int eob;
1296
252k
                        enum TxfmType txtp;
1297
252k
                        if (t->frame_thread.pass) {
1298
252k
                            const int p = t->frame_thread.pass & 1;
1299
252k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
252k
                            cf = ts->frame_thread[p].cf;
1301
252k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
252k
                            eob  = cbi >> 5;
1303
252k
                            txtp = cbi & 0x1f;
1304
252k
                        } 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
252k
                        if (eob >= 0) {
1317
157k
                            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
157k
                            dsp->itx.itxfm_add[b->tx]
1321
157k
                                              [txtp](dst,
1322
157k
                                                     f->cur.stride[0],
1323
157k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
157k
                            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
157k
                        }
1328
767k
                    } 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.01M
                    dst += 4 * t_dim->w;
1333
1.01M
                }
1334
489k
                t->bx -= x;
1335
489k
            }
1336
358k
            t->by -= y;
1337
1338
358k
            if (!has_chroma) continue;
1339
1340
288k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
288k
            if (b->uv_mode == CFL_PRED) {
1343
71.0k
                assert(!init_x && !init_y);
1344
1345
71.0k
                int16_t *const ac = t->scratch.ac;
1346
71.0k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
71.0k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
71.0k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
71.0k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
71.0k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
71.0k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
71.0k
                const int furthest_r =
1354
71.0k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
71.0k
                const int furthest_b =
1356
71.0k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
71.0k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
71.0k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
71.0k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
71.0k
                                                         cbw4 * 4, cbh4 * 4);
1361
213k
                for (int pl = 0; pl < 2; pl++) {
1362
142k
                    if (!b->cfl_alpha[pl]) continue;
1363
124k
                    int angle = 0;
1364
124k
                    const pixel *top_sb_edge = NULL;
1365
124k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
41.3k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
41.3k
                        const int sby = t->by >> f->sb_shift;
1368
41.3k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
41.3k
                    }
1370
124k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
124k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
124k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
124k
                    const enum IntraPredMode m =
1374
124k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
124k
                                                          ypos, ypos > ystart,
1376
124k
                                                          ts->tiling.col_end >> ss_hor,
1377
124k
                                                          ts->tiling.row_end >> ss_ver,
1378
124k
                                                          0, uv_dst[pl], stride,
1379
124k
                                                          top_sb_edge, DC_PRED, &angle,
1380
124k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
124k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
124k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
124k
                                           uv_t_dim->w * 4,
1384
124k
                                           uv_t_dim->h * 4,
1385
124k
                                           ac, b->cfl_alpha[pl]
1386
124k
                                           HIGHBD_CALL_SUFFIX);
1387
124k
                }
1388
71.0k
                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
217k
            } else if (b->pal_sz[1]) {
1394
883
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
883
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
883
                const pixel (*pal)[8];
1397
883
                const uint8_t *pal_idx;
1398
883
                if (t->frame_thread.pass) {
1399
883
                    const int p = t->frame_thread.pass & 1;
1400
883
                    assert(ts->frame_thread[p].pal_idx);
1401
883
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
883
                                              ((t->bx >> 1) + (t->by & 1))];
1403
883
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
883
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
883
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
883
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
883
                                       f->cur.stride[1], pal[1],
1412
883
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
883
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
883
                                       f->cur.stride[1], pal[2],
1415
883
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
883
                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
883
            }
1425
1426
288k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
288k
                                 sm_uv_flag(&t->l, cby4);
1428
288k
            const int uv_sb_has_tr =
1429
288k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
280k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
288k
            const int uv_sb_has_bl =
1432
288k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
280k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
288k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
864k
            for (int pl = 0; pl < 2; pl++) {
1436
1.33M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
760k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
759k
                {
1439
759k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
759k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
759k
                                        ((t->bx + init_x) >> ss_hor));
1442
2.29M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.53M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.53M
                    {
1445
1.53M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.40M
                            b->pal_sz[1])
1447
126k
                        {
1448
126k
                            goto skip_uv_pred;
1449
126k
                        }
1450
1451
1.40M
                        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.40M
                        const enum EdgeFlags edge_flags =
1456
1.40M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
913k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.14M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.40M
                            ((x > (init_x >> ss_hor) ||
1460
633k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
985k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.40M
                        const pixel *top_sb_edge = NULL;
1463
1.40M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
357k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
357k
                            const int sby = t->by >> f->sb_shift;
1466
357k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
357k
                        }
1468
1.40M
                        const enum IntraPredMode uv_mode =
1469
1.40M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.40M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.40M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.40M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.40M
                        const enum IntraPredMode m =
1474
1.40M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.40M
                                                              ypos, ypos > ystart,
1476
1.40M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.40M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.40M
                                                              edge_flags, dst, stride,
1479
1.40M
                                                              top_sb_edge, uv_mode,
1480
1.40M
                                                              &angle, uv_t_dim->w,
1481
1.40M
                                                              uv_t_dim->h,
1482
1.40M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.40M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.40M
                        angle |= intra_edge_filter_flag;
1485
1.40M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.40M
                                                 uv_t_dim->w * 4,
1487
1.40M
                                                 uv_t_dim->h * 4,
1488
1.40M
                                                 angle | sm_uv_fl,
1489
1.40M
                                                 (4 * f->bw + ss_hor -
1490
1.40M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.40M
                                                 (4 * f->bh + ss_ver -
1492
1.40M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.40M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.40M
                        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.53M
                    skip_uv_pred: {}
1505
1.53M
                        if (!b->skip) {
1506
359k
                            enum TxfmType txtp;
1507
359k
                            int eob;
1508
359k
                            coef *cf;
1509
359k
                            if (t->frame_thread.pass) {
1510
359k
                                const int p = t->frame_thread.pass & 1;
1511
359k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
359k
                                cf = ts->frame_thread[p].cf;
1513
359k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
359k
                                eob  = cbi >> 5;
1515
359k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
359k
                            if (eob >= 0) {
1533
106k
                                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
106k
                                dsp->itx.itxfm_add[b->uvtx]
1537
106k
                                                  [txtp](dst, stride,
1538
106k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
106k
                                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
106k
                            }
1543
1.17M
                        } 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.53M
                        dst += uv_t_dim->w * 4;
1548
1.53M
                    }
1549
760k
                    t->bx -= x << ss_hor;
1550
760k
                }
1551
576k
                t->by -= y << ss_ver;
1552
576k
            }
1553
288k
        }
1554
348k
    }
1555
336k
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
178k
{
1180
178k
    Dav1dTileState *const ts = t->ts;
1181
178k
    const Dav1dFrameContext *const f = t->f;
1182
178k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
178k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
178k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
178k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
178k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
178k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
178k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
178k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
178k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
178k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
142k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
136k
                           (bh4 > ss_ver || t->by & 1);
1194
178k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
178k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
178k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
178k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
178k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
363k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
184k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
184k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
375k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
190k
            if (b->pal_sz[0]) {
1208
1.78k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
1.78k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
1.78k
                const uint8_t *pal_idx;
1211
1.78k
                if (t->frame_thread.pass) {
1212
1.78k
                    const int p = t->frame_thread.pass & 1;
1213
1.78k
                    assert(ts->frame_thread[p].pal_idx);
1214
1.78k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
1.78k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
1.78k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
1.78k
                const pixel *const pal = t->frame_thread.pass ?
1220
1.78k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
1.78k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
1.78k
                    bytefn(t->scratch.pal)[0];
1223
1.78k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
1.78k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
1.78k
                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
1.78k
            }
1229
1230
190k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
190k
                                     sm_flag(&t->l, by4) |
1232
190k
                                     intra_edge_filter_flag);
1233
190k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
184k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
190k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
184k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
190k
            int y, x;
1238
190k
            const int sub_w4 = imin(w4, init_x + 16);
1239
444k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
254k
                 y += t_dim->h, t->by += t_dim->h)
1241
253k
            {
1242
253k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
253k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
253k
                                    t->bx + init_x);
1245
726k
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
472k
                     x += t_dim->w, t->bx += t_dim->w)
1247
472k
                {
1248
472k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
469k
                    int angle = b->y_angle;
1251
469k
                    const enum EdgeFlags edge_flags =
1252
469k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
371k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
469k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
307k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
469k
                    const pixel *top_sb_edge = NULL;
1257
469k
                    if (!(t->by & (f->sb_step - 1))) {
1258
113k
                        top_sb_edge = f->ipred_edge[0];
1259
113k
                        const int sby = t->by >> f->sb_shift;
1260
113k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
113k
                    }
1262
469k
                    const enum IntraPredMode m =
1263
469k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
469k
                                                          t->bx > ts->tiling.col_start,
1265
469k
                                                          t->by,
1266
469k
                                                          t->by > ts->tiling.row_start,
1267
469k
                                                          ts->tiling.col_end,
1268
469k
                                                          ts->tiling.row_end,
1269
469k
                                                          edge_flags, dst,
1270
469k
                                                          f->cur.stride[0], top_sb_edge,
1271
469k
                                                          b->y_mode, &angle,
1272
469k
                                                          t_dim->w, t_dim->h,
1273
469k
                                                          f->seq_hdr->intra_edge_filter,
1274
469k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
469k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
469k
                                             t_dim->w * 4, t_dim->h * 4,
1277
469k
                                             angle | intra_flags,
1278
469k
                                             4 * f->bw - 4 * t->bx,
1279
469k
                                             4 * f->bh - 4 * t->by
1280
469k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
469k
                    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
472k
                skip_y_pred: {}
1293
472k
                    if (!b->skip) {
1294
114k
                        coef *cf;
1295
114k
                        int eob;
1296
114k
                        enum TxfmType txtp;
1297
114k
                        if (t->frame_thread.pass) {
1298
114k
                            const int p = t->frame_thread.pass & 1;
1299
114k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
114k
                            cf = ts->frame_thread[p].cf;
1301
114k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
114k
                            eob  = cbi >> 5;
1303
114k
                            txtp = cbi & 0x1f;
1304
114k
                        } else {
1305
0
                            uint8_t cf_ctx;
1306
0
                            cf = bitfn(t->cf);
1307
0
                            eob = decode_coefs(t, &t->a->lcoef[bx4 + x],
1308
0
                                               &t->l.lcoef[by4 + y], b->tx, bs,
1309
0
                                               b, 1, 0, cf, &txtp, &cf_ctx);
1310
0
                            if (DEBUG_BLOCK_INFO)
1311
0
                                printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
1312
0
                                       b->tx, txtp, eob, ts->msac.rng);
1313
0
                            dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
1314
0
                            dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
1315
0
                        }
1316
114k
                        if (eob >= 0) {
1317
72.4k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1318
0
                                coef_dump(cf, imin(t_dim->h, 8) * 4,
1319
0
                                          imin(t_dim->w, 8) * 4, 3, "dq");
1320
72.4k
                            dsp->itx.itxfm_add[b->tx]
1321
72.4k
                                              [txtp](dst,
1322
72.4k
                                                     f->cur.stride[0],
1323
72.4k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
72.4k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1325
0
                                hex_dump(dst, f->cur.stride[0],
1326
0
                                         t_dim->w * 4, t_dim->h * 4, "recon");
1327
72.4k
                        }
1328
358k
                    } 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
472k
                    dst += 4 * t_dim->w;
1333
472k
                }
1334
254k
                t->bx -= x;
1335
254k
            }
1336
190k
            t->by -= y;
1337
1338
190k
            if (!has_chroma) continue;
1339
1340
143k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
143k
            if (b->uv_mode == CFL_PRED) {
1343
37.9k
                assert(!init_x && !init_y);
1344
1345
37.9k
                int16_t *const ac = t->scratch.ac;
1346
37.9k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
37.9k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
37.9k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
37.9k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
37.9k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
37.9k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
37.9k
                const int furthest_r =
1354
37.9k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
37.9k
                const int furthest_b =
1356
37.9k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
37.9k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
37.9k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
37.9k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
37.9k
                                                         cbw4 * 4, cbh4 * 4);
1361
113k
                for (int pl = 0; pl < 2; pl++) {
1362
75.8k
                    if (!b->cfl_alpha[pl]) continue;
1363
67.3k
                    int angle = 0;
1364
67.3k
                    const pixel *top_sb_edge = NULL;
1365
67.3k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
20.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
20.5k
                        const int sby = t->by >> f->sb_shift;
1368
20.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
20.5k
                    }
1370
67.3k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
67.3k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
67.3k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
67.3k
                    const enum IntraPredMode m =
1374
67.3k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
67.3k
                                                          ypos, ypos > ystart,
1376
67.3k
                                                          ts->tiling.col_end >> ss_hor,
1377
67.3k
                                                          ts->tiling.row_end >> ss_ver,
1378
67.3k
                                                          0, uv_dst[pl], stride,
1379
67.3k
                                                          top_sb_edge, DC_PRED, &angle,
1380
67.3k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
67.3k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
67.3k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
67.3k
                                           uv_t_dim->w * 4,
1384
67.3k
                                           uv_t_dim->h * 4,
1385
67.3k
                                           ac, b->cfl_alpha[pl]
1386
67.3k
                                           HIGHBD_CALL_SUFFIX);
1387
67.3k
                }
1388
37.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
105k
            } else if (b->pal_sz[1]) {
1394
413
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
413
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
413
                const pixel (*pal)[8];
1397
413
                const uint8_t *pal_idx;
1398
413
                if (t->frame_thread.pass) {
1399
413
                    const int p = t->frame_thread.pass & 1;
1400
413
                    assert(ts->frame_thread[p].pal_idx);
1401
413
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
413
                                              ((t->bx >> 1) + (t->by & 1))];
1403
413
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
413
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
413
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
413
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
413
                                       f->cur.stride[1], pal[1],
1412
413
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
413
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
413
                                       f->cur.stride[1], pal[2],
1415
413
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
413
                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
413
            }
1425
1426
143k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
143k
                                 sm_uv_flag(&t->l, cby4);
1428
143k
            const int uv_sb_has_tr =
1429
143k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
139k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
143k
            const int uv_sb_has_bl =
1432
143k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
139k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
143k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
428k
            for (int pl = 0; pl < 2; pl++) {
1436
660k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
375k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
374k
                {
1439
374k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
374k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
374k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.04M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
666k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
666k
                    {
1445
666k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
599k
                            b->pal_sz[1])
1447
68.5k
                        {
1448
68.5k
                            goto skip_uv_pred;
1449
68.5k
                        }
1450
1451
598k
                        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
598k
                        const enum EdgeFlags edge_flags =
1456
598k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
370k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
471k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
598k
                            ((x > (init_x >> ss_hor) ||
1460
306k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
393k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
598k
                        const pixel *top_sb_edge = NULL;
1463
598k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
163k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
163k
                            const int sby = t->by >> f->sb_shift;
1466
163k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
163k
                        }
1468
598k
                        const enum IntraPredMode uv_mode =
1469
598k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
598k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
598k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
598k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
598k
                        const enum IntraPredMode m =
1474
598k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
598k
                                                              ypos, ypos > ystart,
1476
598k
                                                              ts->tiling.col_end >> ss_hor,
1477
598k
                                                              ts->tiling.row_end >> ss_ver,
1478
598k
                                                              edge_flags, dst, stride,
1479
598k
                                                              top_sb_edge, uv_mode,
1480
598k
                                                              &angle, uv_t_dim->w,
1481
598k
                                                              uv_t_dim->h,
1482
598k
                                                              f->seq_hdr->intra_edge_filter,
1483
598k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
598k
                        angle |= intra_edge_filter_flag;
1485
598k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
598k
                                                 uv_t_dim->w * 4,
1487
598k
                                                 uv_t_dim->h * 4,
1488
598k
                                                 angle | sm_uv_fl,
1489
598k
                                                 (4 * f->bw + ss_hor -
1490
598k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
598k
                                                 (4 * f->bh + ss_ver -
1492
598k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
598k
                                                 HIGHBD_CALL_SUFFIX);
1494
598k
                        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
666k
                    skip_uv_pred: {}
1505
666k
                        if (!b->skip) {
1506
155k
                            enum TxfmType txtp;
1507
155k
                            int eob;
1508
155k
                            coef *cf;
1509
155k
                            if (t->frame_thread.pass) {
1510
155k
                                const int p = t->frame_thread.pass & 1;
1511
155k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
155k
                                cf = ts->frame_thread[p].cf;
1513
155k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
155k
                                eob  = cbi >> 5;
1515
155k
                                txtp = cbi & 0x1f;
1516
18.4E
                            } else {
1517
18.4E
                                uint8_t cf_ctx;
1518
18.4E
                                cf = bitfn(t->cf);
1519
18.4E
                                eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1520
18.4E
                                                   &t->l.ccoef[pl][cby4 + y],
1521
18.4E
                                                   b->uvtx, bs, b, 1, 1 + pl, cf,
1522
18.4E
                                                   &txtp, &cf_ctx);
1523
18.4E
                                if (DEBUG_BLOCK_INFO)
1524
0
                                    printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1525
0
                                           "txtp=%d,eob=%d]: r=%d [x=%d,cbx4=%d]\n",
1526
0
                                           pl, b->uvtx, txtp, eob, ts->msac.rng, x, cbx4);
1527
18.4E
                                int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1528
18.4E
                                int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
1529
18.4E
                                dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1530
18.4E
                                dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1531
18.4E
                            }
1532
155k
                            if (eob >= 0) {
1533
54.1k
                                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
54.1k
                                dsp->itx.itxfm_add[b->uvtx]
1537
54.1k
                                                  [txtp](dst, stride,
1538
54.1k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
54.1k
                                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
54.1k
                            }
1543
510k
                        } 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
666k
                        dst += uv_t_dim->w * 4;
1548
666k
                    }
1549
375k
                    t->bx -= x << ss_hor;
1550
375k
                }
1551
285k
                t->by -= y << ss_ver;
1552
285k
            }
1553
143k
        }
1554
184k
    }
1555
178k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
157k
{
1180
157k
    Dav1dTileState *const ts = t->ts;
1181
157k
    const Dav1dFrameContext *const f = t->f;
1182
157k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
157k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
157k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
157k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
157k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
157k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
157k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
157k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
157k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
157k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
140k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
137k
                           (bh4 > ss_ver || t->by & 1);
1194
157k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
157k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
157k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
157k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
157k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
321k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
163k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
163k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
332k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
168k
            if (b->pal_sz[0]) {
1208
2.53k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
2.53k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
2.53k
                const uint8_t *pal_idx;
1211
2.53k
                if (t->frame_thread.pass) {
1212
2.53k
                    const int p = t->frame_thread.pass & 1;
1213
2.53k
                    assert(ts->frame_thread[p].pal_idx);
1214
2.53k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
2.53k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
2.53k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
2.53k
                const pixel *const pal = t->frame_thread.pass ?
1220
2.53k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
2.53k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
2.53k
                    bytefn(t->scratch.pal)[0];
1223
2.53k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
2.53k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
2.53k
                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.53k
            }
1229
1230
168k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
168k
                                     sm_flag(&t->l, by4) |
1232
168k
                                     intra_edge_filter_flag);
1233
168k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
163k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
168k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
163k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
168k
            int y, x;
1238
168k
            const int sub_w4 = imin(w4, init_x + 16);
1239
403k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
235k
                 y += t_dim->h, t->by += t_dim->h)
1241
234k
            {
1242
234k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
234k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
234k
                                    t->bx + init_x);
1245
782k
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
547k
                     x += t_dim->w, t->bx += t_dim->w)
1247
547k
                {
1248
547k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
542k
                    int angle = b->y_angle;
1251
542k
                    const enum EdgeFlags edge_flags =
1252
542k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
446k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
542k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
390k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
542k
                    const pixel *top_sb_edge = NULL;
1257
542k
                    if (!(t->by & (f->sb_step - 1))) {
1258
126k
                        top_sb_edge = f->ipred_edge[0];
1259
126k
                        const int sby = t->by >> f->sb_shift;
1260
126k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
126k
                    }
1262
542k
                    const enum IntraPredMode m =
1263
542k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
542k
                                                          t->bx > ts->tiling.col_start,
1265
542k
                                                          t->by,
1266
542k
                                                          t->by > ts->tiling.row_start,
1267
542k
                                                          ts->tiling.col_end,
1268
542k
                                                          ts->tiling.row_end,
1269
542k
                                                          edge_flags, dst,
1270
542k
                                                          f->cur.stride[0], top_sb_edge,
1271
542k
                                                          b->y_mode, &angle,
1272
542k
                                                          t_dim->w, t_dim->h,
1273
542k
                                                          f->seq_hdr->intra_edge_filter,
1274
542k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
542k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
542k
                                             t_dim->w * 4, t_dim->h * 4,
1277
542k
                                             angle | intra_flags,
1278
542k
                                             4 * f->bw - 4 * t->bx,
1279
542k
                                             4 * f->bh - 4 * t->by
1280
542k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
542k
                    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
547k
                skip_y_pred: {}
1293
547k
                    if (!b->skip) {
1294
138k
                        coef *cf;
1295
138k
                        int eob;
1296
138k
                        enum TxfmType txtp;
1297
138k
                        if (t->frame_thread.pass) {
1298
138k
                            const int p = t->frame_thread.pass & 1;
1299
138k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
138k
                            cf = ts->frame_thread[p].cf;
1301
138k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
138k
                            eob  = cbi >> 5;
1303
138k
                            txtp = cbi & 0x1f;
1304
138k
                        } 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
138k
                        if (eob >= 0) {
1317
85.1k
                            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
85.1k
                            dsp->itx.itxfm_add[b->tx]
1321
85.1k
                                              [txtp](dst,
1322
85.1k
                                                     f->cur.stride[0],
1323
85.1k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
85.1k
                            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
85.1k
                        }
1328
409k
                    } 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
547k
                    dst += 4 * t_dim->w;
1333
547k
                }
1334
235k
                t->bx -= x;
1335
235k
            }
1336
168k
            t->by -= y;
1337
1338
168k
            if (!has_chroma) continue;
1339
1340
145k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
145k
            if (b->uv_mode == CFL_PRED) {
1343
33.1k
                assert(!init_x && !init_y);
1344
1345
33.1k
                int16_t *const ac = t->scratch.ac;
1346
33.1k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
33.1k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
33.1k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
33.1k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
33.1k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
33.1k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
33.1k
                const int furthest_r =
1354
33.1k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
33.1k
                const int furthest_b =
1356
33.1k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
33.1k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
33.1k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
33.1k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
33.1k
                                                         cbw4 * 4, cbh4 * 4);
1361
99.3k
                for (int pl = 0; pl < 2; pl++) {
1362
66.2k
                    if (!b->cfl_alpha[pl]) continue;
1363
56.9k
                    int angle = 0;
1364
56.9k
                    const pixel *top_sb_edge = NULL;
1365
56.9k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
20.8k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
20.8k
                        const int sby = t->by >> f->sb_shift;
1368
20.8k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
20.8k
                    }
1370
56.9k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
56.9k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
56.9k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
56.9k
                    const enum IntraPredMode m =
1374
56.9k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
56.9k
                                                          ypos, ypos > ystart,
1376
56.9k
                                                          ts->tiling.col_end >> ss_hor,
1377
56.9k
                                                          ts->tiling.row_end >> ss_ver,
1378
56.9k
                                                          0, uv_dst[pl], stride,
1379
56.9k
                                                          top_sb_edge, DC_PRED, &angle,
1380
56.9k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
56.9k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
56.9k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
56.9k
                                           uv_t_dim->w * 4,
1384
56.9k
                                           uv_t_dim->h * 4,
1385
56.9k
                                           ac, b->cfl_alpha[pl]
1386
56.9k
                                           HIGHBD_CALL_SUFFIX);
1387
56.9k
                }
1388
33.1k
                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
112k
            } else if (b->pal_sz[1]) {
1394
470
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
470
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
470
                const pixel (*pal)[8];
1397
470
                const uint8_t *pal_idx;
1398
470
                if (t->frame_thread.pass) {
1399
470
                    const int p = t->frame_thread.pass & 1;
1400
470
                    assert(ts->frame_thread[p].pal_idx);
1401
470
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
470
                                              ((t->bx >> 1) + (t->by & 1))];
1403
470
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
470
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
470
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
470
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
470
                                       f->cur.stride[1], pal[1],
1412
470
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
470
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
470
                                       f->cur.stride[1], pal[2],
1415
470
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
470
                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
470
            }
1425
1426
145k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
145k
                                 sm_uv_flag(&t->l, cby4);
1428
145k
            const int uv_sb_has_tr =
1429
145k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
141k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
145k
            const int uv_sb_has_bl =
1432
145k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
141k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
145k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
435k
            for (int pl = 0; pl < 2; pl++) {
1436
675k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
385k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
385k
                {
1439
385k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
385k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
385k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.25M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
866k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
866k
                    {
1445
866k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
809k
                            b->pal_sz[1])
1447
58.1k
                        {
1448
58.1k
                            goto skip_uv_pred;
1449
58.1k
                        }
1450
1451
808k
                        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
808k
                        const enum EdgeFlags edge_flags =
1456
808k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
543k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
673k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
808k
                            ((x > (init_x >> ss_hor) ||
1460
327k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
592k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
808k
                        const pixel *top_sb_edge = NULL;
1463
808k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
193k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
193k
                            const int sby = t->by >> f->sb_shift;
1466
193k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
193k
                        }
1468
808k
                        const enum IntraPredMode uv_mode =
1469
808k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
808k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
808k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
808k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
808k
                        const enum IntraPredMode m =
1474
808k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
808k
                                                              ypos, ypos > ystart,
1476
808k
                                                              ts->tiling.col_end >> ss_hor,
1477
808k
                                                              ts->tiling.row_end >> ss_ver,
1478
808k
                                                              edge_flags, dst, stride,
1479
808k
                                                              top_sb_edge, uv_mode,
1480
808k
                                                              &angle, uv_t_dim->w,
1481
808k
                                                              uv_t_dim->h,
1482
808k
                                                              f->seq_hdr->intra_edge_filter,
1483
808k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
808k
                        angle |= intra_edge_filter_flag;
1485
808k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
808k
                                                 uv_t_dim->w * 4,
1487
808k
                                                 uv_t_dim->h * 4,
1488
808k
                                                 angle | sm_uv_fl,
1489
808k
                                                 (4 * f->bw + ss_hor -
1490
808k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
808k
                                                 (4 * f->bh + ss_ver -
1492
808k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
808k
                                                 HIGHBD_CALL_SUFFIX);
1494
808k
                        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
866k
                    skip_uv_pred: {}
1505
866k
                        if (!b->skip) {
1506
203k
                            enum TxfmType txtp;
1507
203k
                            int eob;
1508
203k
                            coef *cf;
1509
203k
                            if (t->frame_thread.pass) {
1510
203k
                                const int p = t->frame_thread.pass & 1;
1511
203k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
203k
                                cf = ts->frame_thread[p].cf;
1513
203k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
203k
                                eob  = cbi >> 5;
1515
203k
                                txtp = cbi & 0x1f;
1516
203k
                            } 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
203k
                            if (eob >= 0) {
1533
52.1k
                                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
52.1k
                                dsp->itx.itxfm_add[b->uvtx]
1537
52.1k
                                                  [txtp](dst, stride,
1538
52.1k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
52.1k
                                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
52.1k
                            }
1543
663k
                        } 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
866k
                        dst += uv_t_dim->w * 4;
1548
866k
                    }
1549
385k
                    t->bx -= x << ss_hor;
1550
385k
                }
1551
290k
                t->by -= y << ss_ver;
1552
290k
            }
1553
145k
        }
1554
163k
    }
1555
157k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
330k
{
1560
330k
    Dav1dTileState *const ts = t->ts;
1561
330k
    const Dav1dFrameContext *const f = t->f;
1562
330k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
330k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
330k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
330k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
330k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
330k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
330k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
330k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
330k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
177k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
167k
                           (bh4 > ss_ver || t->by & 1);
1573
330k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
330k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
330k
    int res;
1576
1577
    // prediction
1578
330k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
330k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
330k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
330k
    const ptrdiff_t uvdstoff =
1582
330k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
330k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
40.4k
        assert(!f->frame_hdr->super_res.enabled);
1586
40.4k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
40.4k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
40.4k
        if (res) return res;
1589
117k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
78.0k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
78.0k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
78.0k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
78.0k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
78.0k
            if (res) return res;
1595
78.0k
        }
1596
290k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
248k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
248k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
248k
        if (imin(bw4, bh4) > 1 &&
1601
148k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
144k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
5.92k
        {
1604
5.92k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
5.92k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
5.92k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
5.92k
            if (res) return res;
1608
242k
        } else {
1609
242k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
242k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
242k
            if (res) return res;
1612
242k
            if (b->motion_mode == MM_OBMC) {
1613
39.5k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
39.5k
                if (res) return res;
1615
39.5k
            }
1616
242k
        }
1617
248k
        if (b->interintra_type) {
1618
6.90k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
6.90k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
5.71k
                                   SMOOTH_PRED : b->interintra_mode;
1621
6.90k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
6.90k
            int angle = 0;
1623
6.90k
            const pixel *top_sb_edge = NULL;
1624
6.90k
            if (!(t->by & (f->sb_step - 1))) {
1625
4.08k
                top_sb_edge = f->ipred_edge[0];
1626
4.08k
                const int sby = t->by >> f->sb_shift;
1627
4.08k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
4.08k
            }
1629
6.90k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
6.90k
                                                  t->by, t->by > ts->tiling.row_start,
1631
6.90k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
6.90k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
6.90k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
6.90k
                                                  HIGHBD_CALL_SUFFIX);
1635
6.90k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
6.90k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
6.90k
                                     HIGHBD_CALL_SUFFIX);
1638
6.90k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
6.90k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
6.90k
        }
1641
1642
248k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
88.4k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
88.4k
        refmvs_block *const *r;
1647
88.4k
        if (is_sub8x8) {
1648
19.9k
            assert(ss_hor == 1);
1649
19.9k
            r = &t->rt.r[(t->by & 31) + 5];
1650
19.9k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
19.9k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
19.9k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.95k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
19.9k
        }
1655
1656
        // chroma prediction
1657
88.4k
        if (is_sub8x8) {
1658
19.4k
            assert(ss_hor == 1);
1659
19.4k
            ptrdiff_t h_off = 0, v_off = 0;
1660
19.4k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
5.75k
                for (int pl = 0; pl < 2; pl++) {
1662
3.83k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.83k
                             NULL, f->cur.stride[1],
1664
3.83k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.83k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.83k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.83k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.83k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.83k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.83k
                    if (res) return res;
1671
3.83k
                }
1672
1.91k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.91k
                h_off = 2;
1674
1.91k
            }
1675
19.4k
            if (bw4 == 1) {
1676
7.40k
                const enum Filter2d left_filter_2d =
1677
7.40k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
22.2k
                for (int pl = 0; pl < 2; pl++) {
1679
14.8k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
14.8k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
14.8k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
14.8k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
14.8k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
14.8k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
14.8k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
14.8k
                    if (res) return res;
1687
14.8k
                }
1688
7.40k
                h_off = 2;
1689
7.40k
            }
1690
19.4k
            if (bh4 == ss_ver) {
1691
13.9k
                const enum Filter2d top_filter_2d =
1692
13.9k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
41.9k
                for (int pl = 0; pl < 2; pl++) {
1694
27.9k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
27.9k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
27.9k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
27.9k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
27.9k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
27.9k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
27.9k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
27.9k
                    if (res) return res;
1702
27.9k
                }
1703
13.9k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
13.9k
            }
1705
58.4k
            for (int pl = 0; pl < 2; pl++) {
1706
38.9k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
38.9k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
38.9k
                         refp, b->ref[0], filter_2d);
1709
38.9k
                if (res) return res;
1710
38.9k
            }
1711
68.9k
        } else {
1712
68.9k
            if (imin(cbw4, cbh4) > 1 &&
1713
29.0k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
26.3k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
3.59k
            {
1716
10.7k
                for (int pl = 0; pl < 2; pl++) {
1717
7.19k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
7.19k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
7.19k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
7.19k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
7.19k
                    if (res) return res;
1722
7.19k
                }
1723
65.3k
            } else {
1724
196k
                for (int pl = 0; pl < 2; pl++) {
1725
130k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
130k
                             NULL, f->cur.stride[1],
1727
130k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
130k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
130k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
130k
                    if (res) return res;
1731
130k
                    if (b->motion_mode == MM_OBMC) {
1732
21.4k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
21.4k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
21.4k
                        if (res) return res;
1735
21.4k
                    }
1736
130k
                }
1737
65.3k
            }
1738
68.9k
            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
5.28k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
15.8k
                for (int pl = 0; pl < 2; pl++) {
1745
10.5k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
10.5k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
10.5k
                    enum IntraPredMode m =
1748
10.5k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
9.12k
                        SMOOTH_PRED : b->interintra_mode;
1750
10.5k
                    int angle = 0;
1751
10.5k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
10.5k
                    const pixel *top_sb_edge = NULL;
1753
10.5k
                    if (!(t->by & (f->sb_step - 1))) {
1754
6.63k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
6.63k
                        const int sby = t->by >> f->sb_shift;
1756
6.63k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
6.63k
                    }
1758
10.5k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
10.5k
                                                          (t->bx >> ss_hor) >
1760
10.5k
                                                              (ts->tiling.col_start >> ss_hor),
1761
10.5k
                                                          t->by >> ss_ver,
1762
10.5k
                                                          (t->by >> ss_ver) >
1763
10.5k
                                                              (ts->tiling.row_start >> ss_ver),
1764
10.5k
                                                          ts->tiling.col_end >> ss_hor,
1765
10.5k
                                                          ts->tiling.row_end >> ss_ver,
1766
10.5k
                                                          0, uvdst, f->cur.stride[1],
1767
10.5k
                                                          top_sb_edge, m,
1768
10.5k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
10.5k
                                                          HIGHBD_CALL_SUFFIX);
1770
10.5k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
10.5k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
10.5k
                                             HIGHBD_CALL_SUFFIX);
1773
10.5k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
10.5k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
10.5k
                }
1776
5.28k
            }
1777
68.9k
        }
1778
1779
248k
    skip_inter_chroma_pred: {}
1780
248k
        t->tl_4x4_filter = filter_2d;
1781
248k
    } else {
1782
41.5k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
41.5k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
41.5k
        int jnt_weight;
1786
41.5k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
41.5k
        const uint8_t *mask;
1788
1789
124k
        for (int i = 0; i < 2; i++) {
1790
82.9k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
82.9k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.65k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.65k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.65k
                if (res) return res;
1796
80.3k
            } else {
1797
80.3k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
80.3k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
80.3k
                if (res) return res;
1800
80.3k
            }
1801
82.9k
        }
1802
41.5k
        switch (b->comp_type) {
1803
25.4k
        case COMP_INTER_AVG:
1804
25.4k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
25.4k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
25.4k
            break;
1807
9.48k
        case COMP_INTER_WEIGHTED_AVG:
1808
9.48k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
9.48k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
9.48k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
9.48k
            break;
1812
4.19k
        case COMP_INTER_SEG:
1813
4.19k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
4.19k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
4.19k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
4.19k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
4.19k
            mask = seg_mask;
1818
4.19k
            break;
1819
2.33k
        case COMP_INTER_WEDGE:
1820
2.33k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
2.33k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
2.33k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
2.33k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
2.33k
            if (has_chroma)
1825
1.97k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
2.33k
            break;
1827
41.5k
        }
1828
1829
        // chroma
1830
78.5k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
157k
            for (int i = 0; i < 2; i++) {
1832
104k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
104k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
16.5k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.65k
                {
1836
1.65k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.65k
                                      b_dim, 1 + pl,
1838
1.65k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.65k
                    if (res) return res;
1840
103k
                } else {
1841
103k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
103k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
103k
                    if (res) return res;
1844
103k
                }
1845
104k
            }
1846
52.3k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
52.3k
            switch (b->comp_type) {
1848
28.1k
            case COMP_INTER_AVG:
1849
28.1k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
28.1k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
28.1k
                            HIGHBD_CALL_SUFFIX);
1852
28.1k
                break;
1853
12.6k
            case COMP_INTER_WEIGHTED_AVG:
1854
12.6k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
12.6k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
12.6k
                              HIGHBD_CALL_SUFFIX);
1857
12.6k
                break;
1858
3.94k
            case COMP_INTER_WEDGE:
1859
11.5k
            case COMP_INTER_SEG:
1860
11.5k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
11.5k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
11.5k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
11.5k
                             HIGHBD_CALL_SUFFIX);
1864
11.5k
                break;
1865
52.3k
            }
1866
52.3k
        }
1867
41.4k
    }
1868
1869
330k
    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
330k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
330k
    if (b->skip) {
1882
        // reset coef contexts
1883
150k
        BlockContext *const a = t->a;
1884
150k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
150k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
150k
        if (has_chroma) {
1887
52.3k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
52.3k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
52.3k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
52.3k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
52.3k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
52.3k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
52.3k
        }
1894
150k
        return 0;
1895
150k
    }
1896
1897
180k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
180k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
180k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
362k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
367k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
184k
            int y_off = !!init_y, y;
1905
184k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
376k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
191k
                 y += ytx->h, y_off++)
1908
191k
            {
1909
191k
                int x, x_off = !!init_x;
1910
398k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
206k
                     x += ytx->w, x_off++)
1912
206k
                {
1913
206k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
206k
                                   x_off, y_off, &dst[x * 4]);
1915
206k
                    t->bx += ytx->w;
1916
206k
                }
1917
191k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
191k
                t->bx -= x;
1919
191k
                t->by += ytx->h;
1920
191k
            }
1921
184k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
184k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
309k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
206k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
206k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
206k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
419k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
213k
                {
1931
213k
                    int x;
1932
213k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
434k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
221k
                    {
1935
221k
                        coef *cf;
1936
221k
                        int eob;
1937
221k
                        enum TxfmType txtp;
1938
221k
                        if (t->frame_thread.pass) {
1939
221k
                            const int p = t->frame_thread.pass & 1;
1940
221k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
221k
                            cf = ts->frame_thread[p].cf;
1942
221k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
221k
                            eob  = cbi >> 5;
1944
221k
                            txtp = cbi & 0x1f;
1945
221k
                        } 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
221k
                        if (eob >= 0) {
1964
45.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
45.7k
                            dsp->itx.itxfm_add[b->uvtx]
1967
45.7k
                                              [txtp](&uvdst[4 * x],
1968
45.7k
                                                     f->cur.stride[1],
1969
45.7k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
45.7k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
45.7k
                        }
1974
221k
                        t->bx += uvtx->w << ss_hor;
1975
221k
                    }
1976
213k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
213k
                    t->bx -= x << ss_hor;
1978
213k
                    t->by += uvtx->h << ss_ver;
1979
213k
                }
1980
206k
                t->by -= y << ss_ver;
1981
206k
            }
1982
184k
        }
1983
182k
    }
1984
180k
    return 0;
1985
330k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
114k
{
1560
114k
    Dav1dTileState *const ts = t->ts;
1561
114k
    const Dav1dFrameContext *const f = t->f;
1562
114k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
114k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
114k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
114k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
114k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
114k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
114k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
114k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
114k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
86.2k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
81.8k
                           (bh4 > ss_ver || t->by & 1);
1573
114k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
114k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
114k
    int res;
1576
1577
    // prediction
1578
114k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
114k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
114k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
114k
    const ptrdiff_t uvdstoff =
1582
114k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
114k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
17.3k
        assert(!f->frame_hdr->super_res.enabled);
1586
17.3k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
17.3k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
17.3k
        if (res) return res;
1589
50.2k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
33.5k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
33.5k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
33.5k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
33.5k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
33.5k
            if (res) return res;
1595
33.5k
        }
1596
96.7k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
78.8k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
78.8k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
78.8k
        if (imin(bw4, bh4) > 1 &&
1601
46.7k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
43.6k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
3.81k
        {
1604
3.81k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
3.81k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
3.81k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
3.81k
            if (res) return res;
1608
75.0k
        } else {
1609
75.0k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
75.0k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
75.0k
            if (res) return res;
1612
75.0k
            if (b->motion_mode == MM_OBMC) {
1613
11.0k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
11.0k
                if (res) return res;
1615
11.0k
            }
1616
75.0k
        }
1617
78.8k
        if (b->interintra_type) {
1618
3.11k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
3.11k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
2.54k
                                   SMOOTH_PRED : b->interintra_mode;
1621
3.11k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
3.11k
            int angle = 0;
1623
3.11k
            const pixel *top_sb_edge = NULL;
1624
3.11k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.95k
                top_sb_edge = f->ipred_edge[0];
1626
1.95k
                const int sby = t->by >> f->sb_shift;
1627
1.95k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.95k
            }
1629
3.11k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
3.11k
                                                  t->by, t->by > ts->tiling.row_start,
1631
3.11k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
3.11k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
3.11k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
3.11k
                                                  HIGHBD_CALL_SUFFIX);
1635
3.11k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
3.11k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
3.11k
                                     HIGHBD_CALL_SUFFIX);
1638
3.11k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
3.11k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
3.11k
        }
1641
1642
78.8k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
46.0k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
46.0k
        refmvs_block *const *r;
1647
46.0k
        if (is_sub8x8) {
1648
7.92k
            assert(ss_hor == 1);
1649
7.92k
            r = &t->rt.r[(t->by & 31) + 5];
1650
7.92k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
7.92k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
7.92k
            if (bw4 == 1 && bh4 == ss_ver)
1653
819
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
7.92k
        }
1655
1656
        // chroma prediction
1657
46.0k
        if (is_sub8x8) {
1658
7.88k
            assert(ss_hor == 1);
1659
7.88k
            ptrdiff_t h_off = 0, v_off = 0;
1660
7.88k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
2.40k
                for (int pl = 0; pl < 2; pl++) {
1662
1.60k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.60k
                             NULL, f->cur.stride[1],
1664
1.60k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.60k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.60k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.60k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.60k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.60k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.60k
                    if (res) return res;
1671
1.60k
                }
1672
803
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
803
                h_off = 2;
1674
803
            }
1675
7.88k
            if (bw4 == 1) {
1676
3.52k
                const enum Filter2d left_filter_2d =
1677
3.52k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
10.5k
                for (int pl = 0; pl < 2; pl++) {
1679
7.04k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
7.04k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
7.04k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
7.04k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
7.04k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
7.04k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
7.04k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
7.04k
                    if (res) return res;
1687
7.04k
                }
1688
3.52k
                h_off = 2;
1689
3.52k
            }
1690
7.88k
            if (bh4 == ss_ver) {
1691
5.16k
                const enum Filter2d top_filter_2d =
1692
5.16k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
15.4k
                for (int pl = 0; pl < 2; pl++) {
1694
10.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
10.3k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
10.3k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
10.3k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
10.3k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
10.3k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
10.3k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
10.3k
                    if (res) return res;
1702
10.3k
                }
1703
5.16k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
5.16k
            }
1705
23.6k
            for (int pl = 0; pl < 2; pl++) {
1706
15.7k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
15.7k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
15.7k
                         refp, b->ref[0], filter_2d);
1709
15.7k
                if (res) return res;
1710
15.7k
            }
1711
38.1k
        } else {
1712
38.1k
            if (imin(cbw4, cbh4) > 1 &&
1713
16.6k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
14.5k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.62k
            {
1716
7.87k
                for (int pl = 0; pl < 2; pl++) {
1717
5.24k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
5.24k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
5.24k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
5.24k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
5.24k
                    if (res) return res;
1722
5.24k
                }
1723
35.5k
            } else {
1724
106k
                for (int pl = 0; pl < 2; pl++) {
1725
71.1k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
71.1k
                             NULL, f->cur.stride[1],
1727
71.1k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
71.1k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
71.1k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
71.1k
                    if (res) return res;
1731
71.1k
                    if (b->motion_mode == MM_OBMC) {
1732
11.1k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
11.1k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
11.1k
                        if (res) return res;
1735
11.1k
                    }
1736
71.1k
                }
1737
35.5k
            }
1738
38.1k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
2.87k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
8.61k
                for (int pl = 0; pl < 2; pl++) {
1745
5.74k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
5.74k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
5.74k
                    enum IntraPredMode m =
1748
5.74k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
4.79k
                        SMOOTH_PRED : b->interintra_mode;
1750
5.74k
                    int angle = 0;
1751
5.74k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
5.74k
                    const pixel *top_sb_edge = NULL;
1753
5.74k
                    if (!(t->by & (f->sb_step - 1))) {
1754
3.56k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
3.56k
                        const int sby = t->by >> f->sb_shift;
1756
3.56k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
3.56k
                    }
1758
5.74k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
5.74k
                                                          (t->bx >> ss_hor) >
1760
5.74k
                                                              (ts->tiling.col_start >> ss_hor),
1761
5.74k
                                                          t->by >> ss_ver,
1762
5.74k
                                                          (t->by >> ss_ver) >
1763
5.74k
                                                              (ts->tiling.row_start >> ss_ver),
1764
5.74k
                                                          ts->tiling.col_end >> ss_hor,
1765
5.74k
                                                          ts->tiling.row_end >> ss_ver,
1766
5.74k
                                                          0, uvdst, f->cur.stride[1],
1767
5.74k
                                                          top_sb_edge, m,
1768
5.74k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
5.74k
                                                          HIGHBD_CALL_SUFFIX);
1770
5.74k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
5.74k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
5.74k
                                             HIGHBD_CALL_SUFFIX);
1773
5.74k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
5.74k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
5.74k
                }
1776
2.87k
            }
1777
38.1k
        }
1778
1779
78.8k
    skip_inter_chroma_pred: {}
1780
78.8k
        t->tl_4x4_filter = filter_2d;
1781
78.8k
    } else {
1782
17.8k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
17.8k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
17.8k
        int jnt_weight;
1786
17.8k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
17.8k
        const uint8_t *mask;
1788
1789
53.6k
        for (int i = 0; i < 2; i++) {
1790
35.7k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
35.7k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.53k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.53k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.53k
                if (res) return res;
1796
34.2k
            } else {
1797
34.2k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
34.2k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
34.2k
                if (res) return res;
1800
34.2k
            }
1801
35.7k
        }
1802
17.8k
        switch (b->comp_type) {
1803
11.4k
        case COMP_INTER_AVG:
1804
11.4k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
11.4k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
11.4k
            break;
1807
3.37k
        case COMP_INTER_WEIGHTED_AVG:
1808
3.37k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
3.37k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
3.37k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
3.37k
            break;
1812
2.01k
        case COMP_INTER_SEG:
1813
2.01k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
2.01k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
2.01k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
2.01k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
2.01k
            mask = seg_mask;
1818
2.01k
            break;
1819
1.04k
        case COMP_INTER_WEDGE:
1820
1.04k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.04k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.04k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.04k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.04k
            if (has_chroma)
1825
912
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.04k
            break;
1827
17.8k
        }
1828
1829
        // chroma
1830
41.4k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
82.9k
            for (int i = 0; i < 2; i++) {
1832
55.2k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
55.2k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
8.64k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.03k
                {
1836
1.03k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.03k
                                      b_dim, 1 + pl,
1838
1.03k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.03k
                    if (res) return res;
1840
54.2k
                } else {
1841
54.2k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
54.2k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
54.2k
                    if (res) return res;
1844
54.2k
                }
1845
55.2k
            }
1846
27.6k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
27.6k
            switch (b->comp_type) {
1848
15.6k
            case COMP_INTER_AVG:
1849
15.6k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
15.6k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
15.6k
                            HIGHBD_CALL_SUFFIX);
1852
15.6k
                break;
1853
6.57k
            case COMP_INTER_WEIGHTED_AVG:
1854
6.57k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
6.57k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
6.57k
                              HIGHBD_CALL_SUFFIX);
1857
6.57k
                break;
1858
1.82k
            case COMP_INTER_WEDGE:
1859
5.46k
            case COMP_INTER_SEG:
1860
5.46k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
5.46k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
5.46k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
5.46k
                             HIGHBD_CALL_SUFFIX);
1864
5.46k
                break;
1865
27.6k
            }
1866
27.6k
        }
1867
17.8k
    }
1868
1869
114k
    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
114k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
114k
    if (b->skip) {
1882
        // reset coef contexts
1883
43.1k
        BlockContext *const a = t->a;
1884
43.1k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
43.1k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
43.1k
        if (has_chroma) {
1887
28.4k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
28.4k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
28.4k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
28.4k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
28.4k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
28.4k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
28.4k
        }
1894
43.1k
        return 0;
1895
43.1k
    }
1896
1897
70.9k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
70.9k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
70.9k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
142k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
144k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
72.7k
            int y_off = !!init_y, y;
1905
72.7k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
147k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
74.7k
                 y += ytx->h, y_off++)
1908
74.7k
            {
1909
74.7k
                int x, x_off = !!init_x;
1910
155k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
81.0k
                     x += ytx->w, x_off++)
1912
81.0k
                {
1913
81.0k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
81.0k
                                   x_off, y_off, &dst[x * 4]);
1915
81.0k
                    t->bx += ytx->w;
1916
81.0k
                }
1917
74.7k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
74.7k
                t->bx -= x;
1919
74.7k
                t->by += ytx->h;
1920
74.7k
            }
1921
72.7k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
72.7k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
146k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
97.9k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
97.9k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
97.9k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
198k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
100k
                {
1931
100k
                    int x;
1932
100k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
205k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
104k
                    {
1935
104k
                        coef *cf;
1936
104k
                        int eob;
1937
104k
                        enum TxfmType txtp;
1938
104k
                        if (t->frame_thread.pass) {
1939
104k
                            const int p = t->frame_thread.pass & 1;
1940
104k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
104k
                            cf = ts->frame_thread[p].cf;
1942
104k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
104k
                            eob  = cbi >> 5;
1944
104k
                            txtp = cbi & 0x1f;
1945
104k
                        } 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
104k
                        if (eob >= 0) {
1964
24.2k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
24.2k
                            dsp->itx.itxfm_add[b->uvtx]
1967
24.2k
                                              [txtp](&uvdst[4 * x],
1968
24.2k
                                                     f->cur.stride[1],
1969
24.2k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
24.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
24.2k
                        }
1974
104k
                        t->bx += uvtx->w << ss_hor;
1975
104k
                    }
1976
100k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
100k
                    t->bx -= x << ss_hor;
1978
100k
                    t->by += uvtx->h << ss_ver;
1979
100k
                }
1980
97.9k
                t->by -= y << ss_ver;
1981
97.9k
            }
1982
72.7k
        }
1983
71.8k
    }
1984
70.9k
    return 0;
1985
114k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
216k
{
1560
216k
    Dav1dTileState *const ts = t->ts;
1561
216k
    const Dav1dFrameContext *const f = t->f;
1562
216k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
216k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
216k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
216k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
216k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
216k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
216k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
216k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
216k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
91.1k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
86.0k
                           (bh4 > ss_ver || t->by & 1);
1573
216k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
216k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
216k
    int res;
1576
1577
    // prediction
1578
216k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
216k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
216k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
216k
    const ptrdiff_t uvdstoff =
1582
216k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
216k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
23.1k
        assert(!f->frame_hdr->super_res.enabled);
1586
23.1k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
23.1k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
23.1k
        if (res) return res;
1589
66.8k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
44.5k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
44.5k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
44.5k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
44.5k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
44.5k
            if (res) return res;
1595
44.5k
        }
1596
193k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
169k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
169k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
169k
        if (imin(bw4, bh4) > 1 &&
1601
101k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
100k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
2.10k
        {
1604
2.10k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
2.10k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
2.10k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
2.10k
            if (res) return res;
1608
167k
        } else {
1609
167k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
167k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
167k
            if (res) return res;
1612
167k
            if (b->motion_mode == MM_OBMC) {
1613
28.4k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
28.4k
                if (res) return res;
1615
28.4k
            }
1616
167k
        }
1617
169k
        if (b->interintra_type) {
1618
3.79k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
3.79k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
3.17k
                                   SMOOTH_PRED : b->interintra_mode;
1621
3.79k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
3.79k
            int angle = 0;
1623
3.79k
            const pixel *top_sb_edge = NULL;
1624
3.79k
            if (!(t->by & (f->sb_step - 1))) {
1625
2.12k
                top_sb_edge = f->ipred_edge[0];
1626
2.12k
                const int sby = t->by >> f->sb_shift;
1627
2.12k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
2.12k
            }
1629
3.79k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
3.79k
                                                  t->by, t->by > ts->tiling.row_start,
1631
3.79k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
3.79k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
3.79k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
3.79k
                                                  HIGHBD_CALL_SUFFIX);
1635
3.79k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
3.79k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
3.79k
                                     HIGHBD_CALL_SUFFIX);
1638
3.79k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
3.79k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
3.79k
        }
1641
1642
169k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
42.3k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
42.3k
        refmvs_block *const *r;
1647
42.3k
        if (is_sub8x8) {
1648
12.0k
            assert(ss_hor == 1);
1649
12.0k
            r = &t->rt.r[(t->by & 31) + 5];
1650
12.0k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
12.0k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
12.0k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.13k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
12.0k
        }
1655
1656
        // chroma prediction
1657
42.3k
        if (is_sub8x8) {
1658
11.5k
            assert(ss_hor == 1);
1659
11.5k
            ptrdiff_t h_off = 0, v_off = 0;
1660
11.5k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
3.34k
                for (int pl = 0; pl < 2; pl++) {
1662
2.22k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
2.22k
                             NULL, f->cur.stride[1],
1664
2.22k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
2.22k
                             r[-1][t->bx - 1].mv.mv[0],
1666
2.22k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
2.22k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
2.22k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
2.22k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
2.22k
                    if (res) return res;
1671
2.22k
                }
1672
1.11k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.11k
                h_off = 2;
1674
1.11k
            }
1675
11.5k
            if (bw4 == 1) {
1676
3.88k
                const enum Filter2d left_filter_2d =
1677
3.88k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
11.6k
                for (int pl = 0; pl < 2; pl++) {
1679
7.76k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
7.76k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
7.76k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
7.76k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
7.76k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
7.76k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
7.76k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
7.76k
                    if (res) return res;
1687
7.76k
                }
1688
3.88k
                h_off = 2;
1689
3.88k
            }
1690
11.5k
            if (bh4 == ss_ver) {
1691
8.82k
                const enum Filter2d top_filter_2d =
1692
8.82k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
26.4k
                for (int pl = 0; pl < 2; pl++) {
1694
17.6k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
17.6k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
17.6k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
17.6k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
17.6k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
17.6k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
17.6k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
17.6k
                    if (res) return res;
1702
17.6k
                }
1703
8.82k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
8.82k
            }
1705
34.7k
            for (int pl = 0; pl < 2; pl++) {
1706
23.1k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
23.1k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
23.1k
                         refp, b->ref[0], filter_2d);
1709
23.1k
                if (res) return res;
1710
23.1k
            }
1711
30.7k
        } else {
1712
30.7k
            if (imin(cbw4, cbh4) > 1 &&
1713
12.4k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
11.7k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
971
            {
1716
2.91k
                for (int pl = 0; pl < 2; pl++) {
1717
1.94k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
1.94k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
1.94k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
1.94k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
1.94k
                    if (res) return res;
1722
1.94k
                }
1723
29.7k
            } else {
1724
89.4k
                for (int pl = 0; pl < 2; pl++) {
1725
59.6k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
59.6k
                             NULL, f->cur.stride[1],
1727
59.6k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
59.6k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
59.6k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
59.6k
                    if (res) return res;
1731
59.6k
                    if (b->motion_mode == MM_OBMC) {
1732
10.2k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
10.2k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
10.2k
                        if (res) return res;
1735
10.2k
                    }
1736
59.6k
                }
1737
29.7k
            }
1738
30.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
2.41k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
7.24k
                for (int pl = 0; pl < 2; pl++) {
1745
4.82k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
4.82k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
4.82k
                    enum IntraPredMode m =
1748
4.82k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
4.32k
                        SMOOTH_PRED : b->interintra_mode;
1750
4.82k
                    int angle = 0;
1751
4.82k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
4.82k
                    const pixel *top_sb_edge = NULL;
1753
4.82k
                    if (!(t->by & (f->sb_step - 1))) {
1754
3.06k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
3.06k
                        const int sby = t->by >> f->sb_shift;
1756
3.06k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
3.06k
                    }
1758
4.82k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
4.82k
                                                          (t->bx >> ss_hor) >
1760
4.82k
                                                              (ts->tiling.col_start >> ss_hor),
1761
4.82k
                                                          t->by >> ss_ver,
1762
4.82k
                                                          (t->by >> ss_ver) >
1763
4.82k
                                                              (ts->tiling.row_start >> ss_ver),
1764
4.82k
                                                          ts->tiling.col_end >> ss_hor,
1765
4.82k
                                                          ts->tiling.row_end >> ss_ver,
1766
4.82k
                                                          0, uvdst, f->cur.stride[1],
1767
4.82k
                                                          top_sb_edge, m,
1768
4.82k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
4.82k
                                                          HIGHBD_CALL_SUFFIX);
1770
4.82k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
4.82k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
4.82k
                                             HIGHBD_CALL_SUFFIX);
1773
4.82k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
4.82k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
4.82k
                }
1776
2.41k
            }
1777
30.7k
        }
1778
1779
169k
    skip_inter_chroma_pred: {}
1780
169k
        t->tl_4x4_filter = filter_2d;
1781
169k
    } else {
1782
23.6k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
23.6k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
23.6k
        int jnt_weight;
1786
23.6k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
23.6k
        const uint8_t *mask;
1788
1789
70.8k
        for (int i = 0; i < 2; i++) {
1790
47.2k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
47.2k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.12k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.12k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.12k
                if (res) return res;
1796
46.1k
            } else {
1797
46.1k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
46.1k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
46.1k
                if (res) return res;
1800
46.1k
            }
1801
47.2k
        }
1802
23.6k
        switch (b->comp_type) {
1803
14.0k
        case COMP_INTER_AVG:
1804
14.0k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
14.0k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
14.0k
            break;
1807
6.10k
        case COMP_INTER_WEIGHTED_AVG:
1808
6.10k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
6.10k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
6.10k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
6.10k
            break;
1812
2.18k
        case COMP_INTER_SEG:
1813
2.18k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
2.18k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
2.18k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
2.18k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
2.18k
            mask = seg_mask;
1818
2.18k
            break;
1819
1.28k
        case COMP_INTER_WEDGE:
1820
1.28k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.28k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.28k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.28k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.28k
            if (has_chroma)
1825
1.06k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.28k
            break;
1827
23.6k
        }
1828
1829
        // chroma
1830
37.1k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
74.2k
            for (int i = 0; i < 2; i++) {
1832
49.4k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
49.4k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
7.87k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
622
                {
1836
622
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
622
                                      b_dim, 1 + pl,
1838
622
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
622
                    if (res) return res;
1840
48.8k
                } else {
1841
48.8k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
48.8k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
48.8k
                    if (res) return res;
1844
48.8k
                }
1845
49.4k
            }
1846
24.7k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
24.7k
            switch (b->comp_type) {
1848
12.5k
            case COMP_INTER_AVG:
1849
12.5k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
12.5k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
12.5k
                            HIGHBD_CALL_SUFFIX);
1852
12.5k
                break;
1853
6.09k
            case COMP_INTER_WEIGHTED_AVG:
1854
6.09k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
6.09k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
6.09k
                              HIGHBD_CALL_SUFFIX);
1857
6.09k
                break;
1858
2.12k
            case COMP_INTER_WEDGE:
1859
6.10k
            case COMP_INTER_SEG:
1860
6.10k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
6.10k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
6.10k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
6.10k
                             HIGHBD_CALL_SUFFIX);
1864
6.10k
                break;
1865
24.7k
            }
1866
24.7k
        }
1867
23.6k
    }
1868
1869
216k
    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
216k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
216k
    if (b->skip) {
1882
        // reset coef contexts
1883
107k
        BlockContext *const a = t->a;
1884
107k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
107k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
107k
        if (has_chroma) {
1887
23.9k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
23.9k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
23.9k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
23.9k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
23.9k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
23.9k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
23.9k
        }
1894
107k
        return 0;
1895
107k
    }
1896
1897
109k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
109k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
109k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
219k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
222k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
112k
            int y_off = !!init_y, y;
1905
112k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
229k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
117k
                 y += ytx->h, y_off++)
1908
117k
            {
1909
117k
                int x, x_off = !!init_x;
1910
242k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
125k
                     x += ytx->w, x_off++)
1912
125k
                {
1913
125k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
125k
                                   x_off, y_off, &dst[x * 4]);
1915
125k
                    t->bx += ytx->w;
1916
125k
                }
1917
117k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
117k
                t->bx -= x;
1919
117k
                t->by += ytx->h;
1920
117k
            }
1921
112k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
112k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
162k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
108k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
108k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
108k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
220k
                     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
229k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
116k
                    {
1935
116k
                        coef *cf;
1936
116k
                        int eob;
1937
116k
                        enum TxfmType txtp;
1938
116k
                        if (t->frame_thread.pass) {
1939
116k
                            const int p = t->frame_thread.pass & 1;
1940
116k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
116k
                            cf = ts->frame_thread[p].cf;
1942
116k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
116k
                            eob  = cbi >> 5;
1944
116k
                            txtp = cbi & 0x1f;
1945
116k
                        } 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
116k
                        if (eob >= 0) {
1964
21.5k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
21.5k
                            dsp->itx.itxfm_add[b->uvtx]
1967
21.5k
                                              [txtp](&uvdst[4 * x],
1968
21.5k
                                                     f->cur.stride[1],
1969
21.5k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
21.5k
                            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
21.5k
                        }
1974
116k
                        t->bx += uvtx->w << ss_hor;
1975
116k
                    }
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
108k
                t->by -= y << ss_ver;
1981
108k
            }
1982
112k
        }
1983
110k
    }
1984
109k
    return 0;
1985
216k
}
1986
1987
147k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
147k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
147k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
147k
    const int y = sby * f->sb_step * 4;
1994
147k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
147k
    pixel *const p[3] = {
1996
147k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
147k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
147k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
147k
    };
2000
147k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
147k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
147k
                                        f->lf.start_of_tile_row[sby]);
2003
147k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
57.1k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
57.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
57.1k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
57.1k
    const int y = sby * f->sb_step * 4;
1994
57.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
57.1k
    pixel *const p[3] = {
1996
57.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
57.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
57.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
57.1k
    };
2000
57.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
57.1k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
57.1k
                                        f->lf.start_of_tile_row[sby]);
2003
57.1k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
90.1k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
90.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
90.1k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
90.1k
    const int y = sby * f->sb_step * 4;
1994
90.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
90.1k
    pixel *const p[3] = {
1996
90.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
90.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
90.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
90.1k
    };
2000
90.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
90.1k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
90.1k
                                        f->lf.start_of_tile_row[sby]);
2003
90.1k
}
2004
2005
166k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
166k
    const int y = sby * f->sb_step * 4;
2007
166k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
166k
    pixel *const p[3] = {
2009
166k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
166k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
166k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
166k
    };
2013
166k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
166k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
166k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
147k
    {
2017
147k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
147k
    }
2019
166k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
126k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
126k
    }
2023
166k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
68.2k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
68.2k
    const int y = sby * f->sb_step * 4;
2007
68.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
68.2k
    pixel *const p[3] = {
2009
68.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
68.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
68.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
68.2k
    };
2013
68.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
68.2k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
68.2k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
57.1k
    {
2017
57.1k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
57.1k
    }
2019
68.2k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
47.1k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
47.1k
    }
2023
68.2k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
98.3k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
98.3k
    const int y = sby * f->sb_step * 4;
2007
98.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
98.3k
    pixel *const p[3] = {
2009
98.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
98.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
98.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
98.3k
    };
2013
98.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
98.3k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
98.3k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
90.1k
    {
2017
90.1k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
90.1k
    }
2019
98.3k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
79.3k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
79.3k
    }
2023
98.3k
}
2024
2025
75.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
75.7k
    const Dav1dFrameContext *const f = tc->f;
2027
75.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
75.7k
    const int sbsz = f->sb_step;
2029
75.7k
    const int y = sby * sbsz * 4;
2030
75.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
75.7k
    pixel *const p[3] = {
2032
75.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
75.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
75.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
75.7k
    };
2036
75.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
75.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
75.7k
    const int start = sby * sbsz;
2039
75.7k
    if (sby) {
2040
35.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
35.2k
        pixel *p_up[3] = {
2042
35.2k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
35.2k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
35.2k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
35.2k
        };
2046
35.2k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
35.2k
    }
2048
75.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
75.7k
    const int end = imin(start + n_blks, f->bh);
2050
75.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
75.7k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
37.4k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
37.4k
    const Dav1dFrameContext *const f = tc->f;
2027
37.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
37.4k
    const int sbsz = f->sb_step;
2029
37.4k
    const int y = sby * sbsz * 4;
2030
37.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
37.4k
    pixel *const p[3] = {
2032
37.4k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
37.4k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
37.4k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
37.4k
    };
2036
37.4k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
37.4k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
37.4k
    const int start = sby * sbsz;
2039
37.4k
    if (sby) {
2040
19.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
19.2k
        pixel *p_up[3] = {
2042
19.2k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
19.2k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
19.2k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
19.2k
        };
2046
19.2k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
19.2k
    }
2048
37.4k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
37.4k
    const int end = imin(start + n_blks, f->bh);
2050
37.4k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
37.4k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
38.3k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
38.3k
    const Dav1dFrameContext *const f = tc->f;
2027
38.3k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
38.3k
    const int sbsz = f->sb_step;
2029
38.3k
    const int y = sby * sbsz * 4;
2030
38.3k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
38.3k
    pixel *const p[3] = {
2032
38.3k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
38.3k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
38.3k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
38.3k
    };
2036
38.3k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
38.3k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
38.3k
    const int start = sby * sbsz;
2039
38.3k
    if (sby) {
2040
16.0k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
16.0k
        pixel *p_up[3] = {
2042
16.0k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
16.0k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
16.0k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
16.0k
        };
2046
16.0k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
16.0k
    }
2048
38.3k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
38.3k
    const int end = imin(start + n_blks, f->bh);
2050
38.3k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
38.3k
}
2052
2053
28.6k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
28.6k
    const int sbsz = f->sb_step;
2055
28.6k
    const int y = sby * sbsz * 4;
2056
28.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
28.6k
    const pixel *const p[3] = {
2058
28.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
28.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
28.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
28.6k
    };
2062
28.6k
    pixel *const sr_p[3] = {
2063
28.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
28.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
28.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
28.6k
    };
2067
28.6k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
109k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
81.2k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
81.2k
        const int h_start = 8 * !!sby >> ss_ver;
2071
81.2k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
81.2k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
81.2k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
81.2k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
81.2k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
81.2k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
81.2k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
81.2k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
81.2k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
81.2k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
81.2k
                          imin(img_h, h_end) + h_start, src_w,
2083
81.2k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
81.2k
                          HIGHBD_CALL_SUFFIX);
2085
81.2k
    }
2086
28.6k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
10.8k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
10.8k
    const int sbsz = f->sb_step;
2055
10.8k
    const int y = sby * sbsz * 4;
2056
10.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
10.8k
    const pixel *const p[3] = {
2058
10.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
10.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
10.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
10.8k
    };
2062
10.8k
    pixel *const sr_p[3] = {
2063
10.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
10.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
10.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
10.8k
    };
2067
10.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
41.9k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
31.1k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
31.1k
        const int h_start = 8 * !!sby >> ss_ver;
2071
31.1k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
31.1k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
31.1k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
31.1k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
31.1k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
31.1k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
31.1k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
31.1k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
31.1k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
31.1k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
31.1k
                          imin(img_h, h_end) + h_start, src_w,
2083
31.1k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
31.1k
                          HIGHBD_CALL_SUFFIX);
2085
31.1k
    }
2086
10.8k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
17.8k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
17.8k
    const int sbsz = f->sb_step;
2055
17.8k
    const int y = sby * sbsz * 4;
2056
17.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
17.8k
    const pixel *const p[3] = {
2058
17.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
17.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
17.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
17.8k
    };
2062
17.8k
    pixel *const sr_p[3] = {
2063
17.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
17.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
17.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
17.8k
    };
2067
17.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
67.9k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
50.0k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
50.0k
        const int h_start = 8 * !!sby >> ss_ver;
2071
50.0k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
50.0k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
50.0k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
50.0k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
50.0k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
50.0k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
50.0k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
50.0k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
50.0k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
50.0k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
50.0k
                          imin(img_h, h_end) + h_start, src_w,
2083
50.0k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
50.0k
                          HIGHBD_CALL_SUFFIX);
2085
50.0k
    }
2086
17.8k
}
2087
2088
96.5k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
96.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
96.5k
    const int y = sby * f->sb_step * 4;
2091
96.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
96.5k
    pixel *const sr_p[3] = {
2093
96.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
96.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
96.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
96.5k
    };
2097
96.5k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
96.5k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
32.9k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
32.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
32.9k
    const int y = sby * f->sb_step * 4;
2091
32.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
32.9k
    pixel *const sr_p[3] = {
2093
32.9k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
32.9k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
32.9k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
32.9k
    };
2097
32.9k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
32.9k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
63.6k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
63.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
63.6k
    const int y = sby * f->sb_step * 4;
2091
63.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
63.6k
    pixel *const sr_p[3] = {
2093
63.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
63.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
63.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
63.6k
    };
2097
63.6k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
63.6k
}
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
190k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
190k
    const Dav1dFrameContext *const f = t->f;
2113
190k
    Dav1dTileState *const ts = t->ts;
2114
190k
    const int sby = t->by >> f->sb_shift;
2115
190k
    const int sby_off = f->sb128w * 128 * sby;
2116
190k
    const int x_off = ts->tiling.col_start;
2117
2118
190k
    const pixel *const y =
2119
190k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
190k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
190k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
190k
               4 * (ts->tiling.col_end - x_off));
2123
2124
190k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
135k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
135k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
135k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
135k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
407k
        for (int pl = 1; pl <= 2; pl++)
2131
271k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
133k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
133k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
135k
    }
2135
190k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
80.4k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
80.4k
    const Dav1dFrameContext *const f = t->f;
2113
80.4k
    Dav1dTileState *const ts = t->ts;
2114
80.4k
    const int sby = t->by >> f->sb_shift;
2115
80.4k
    const int sby_off = f->sb128w * 128 * sby;
2116
80.4k
    const int x_off = ts->tiling.col_start;
2117
2118
80.4k
    const pixel *const y =
2119
80.4k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
80.4k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
80.4k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
80.4k
               4 * (ts->tiling.col_end - x_off));
2123
2124
80.4k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
66.5k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
66.5k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
66.5k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
66.5k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
199k
        for (int pl = 1; pl <= 2; pl++)
2131
133k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
133k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
133k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
66.5k
    }
2135
80.4k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
109k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
109k
    const Dav1dFrameContext *const f = t->f;
2113
109k
    Dav1dTileState *const ts = t->ts;
2114
109k
    const int sby = t->by >> f->sb_shift;
2115
109k
    const int sby_off = f->sb128w * 128 * sby;
2116
109k
    const int x_off = ts->tiling.col_start;
2117
2118
109k
    const pixel *const y =
2119
109k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
109k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
109k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
109k
               4 * (ts->tiling.col_end - x_off));
2123
2124
109k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
69.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
69.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
69.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
69.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
207k
        for (int pl = 1; pl <= 2; pl++)
2131
138k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
69.1k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
69.1k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
69.1k
    }
2135
109k
}
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
11.7k
{
2142
11.7k
    const Dav1dFrameContext *const f = t->f;
2143
11.7k
    pixel *const pal = t->frame_thread.pass ?
2144
11.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
11.7k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
18.4E
        bytefn(t->scratch.pal)[0];
2147
56.3k
    for (int x = 0; x < bw4; x++)
2148
44.5k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
49.0k
    for (int y = 0; y < bh4; y++)
2150
37.3k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
11.7k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
5.74k
{
2142
5.74k
    const Dav1dFrameContext *const f = t->f;
2143
5.74k
    pixel *const pal = t->frame_thread.pass ?
2144
5.74k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
5.74k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
5.74k
        bytefn(t->scratch.pal)[0];
2147
28.1k
    for (int x = 0; x < bw4; x++)
2148
22.3k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
24.0k
    for (int y = 0; y < bh4; y++)
2150
18.2k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
5.74k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
6.00k
{
2142
6.00k
    const Dav1dFrameContext *const f = t->f;
2143
6.00k
    pixel *const pal = t->frame_thread.pass ?
2144
6.00k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
6.00k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
18.4E
        bytefn(t->scratch.pal)[0];
2147
28.1k
    for (int x = 0; x < bw4; x++)
2148
22.1k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
25.0k
    for (int y = 0; y < bh4; y++)
2150
19.0k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
6.00k
}
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
3.89k
{
2158
3.89k
    const Dav1dFrameContext *const f = t->f;
2159
3.89k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
3.89k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
3.89k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
3.89k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
11.6k
    for (int pl = 1; pl <= 2; pl++) {
2165
53.6k
        for (int x = 0; x < bw4; x++)
2166
45.8k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
42.0k
        for (int y = 0; y < bh4; y++)
2168
34.2k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
7.78k
    }
2170
3.89k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
2.01k
{
2158
2.01k
    const Dav1dFrameContext *const f = t->f;
2159
2.01k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
2.01k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
2.01k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
2.01k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
6.05k
    for (int pl = 1; pl <= 2; pl++) {
2165
27.6k
        for (int x = 0; x < bw4; x++)
2166
23.5k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
22.1k
        for (int y = 0; y < bh4; y++)
2168
18.0k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
4.03k
    }
2170
2.01k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
1.87k
{
2158
1.87k
    const Dav1dFrameContext *const f = t->f;
2159
1.87k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
1.87k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
1.87k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
1.87k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
5.61k
    for (int pl = 1; pl <= 2; pl++) {
2165
26.0k
        for (int x = 0; x < bw4; x++)
2166
22.2k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
19.9k
        for (int y = 0; y < bh4; y++)
2168
16.1k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
3.74k
    }
2170
1.87k
}
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
15.6k
{
2176
15.6k
    Dav1dTileState *const ts = t->ts;
2177
15.6k
    const Dav1dFrameContext *const f = t->f;
2178
15.6k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
15.6k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
15.6k
    pixel cache[16], used_cache[8];
2181
15.6k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
15.6k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
15.6k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
15.6k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
15.6k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
25.9k
    while (l_cache && a_cache) {
2190
10.2k
        if (*l < *a) {
2191
3.64k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
3.60k
                cache[n_cache++] = *l;
2193
3.64k
            l++;
2194
3.64k
            l_cache--;
2195
6.62k
        } else {
2196
6.62k
            if (*a == *l) {
2197
2.60k
                l++;
2198
2.60k
                l_cache--;
2199
2.60k
            }
2200
6.62k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
6.28k
                cache[n_cache++] = *a;
2202
6.62k
            a++;
2203
6.62k
            a_cache--;
2204
6.62k
        }
2205
10.2k
    }
2206
15.6k
    if (l_cache) {
2207
17.6k
        do {
2208
17.6k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
13.7k
                cache[n_cache++] = *l;
2210
17.6k
            l++;
2211
17.6k
        } while (--l_cache > 0);
2212
11.6k
    } else if (a_cache) {
2213
11.7k
        do {
2214
11.7k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
9.50k
                cache[n_cache++] = *a;
2216
11.7k
            a++;
2217
11.7k
        } while (--a_cache > 0);
2218
2.89k
    }
2219
2220
    // find reused cache entries
2221
15.6k
    int i = 0;
2222
45.3k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
29.6k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
14.3k
            used_cache[i++] = cache[n];
2225
15.6k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
15.6k
    pixel *const pal = t->frame_thread.pass ?
2229
15.6k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
15.6k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
15.6k
        bytefn(t->scratch.pal)[pl];
2232
15.6k
    if (i < pal_sz) {
2233
13.8k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
13.8k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
13.8k
        if (i < pal_sz) {
2237
12.7k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
12.7k
            const int max = (1 << bpc) - 1;
2239
2240
29.6k
            do {
2241
29.6k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
29.6k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
29.6k
                if (prev + !pl >= max) {
2244
18.4k
                    for (; i < pal_sz; i++)
2245
11.9k
                        pal[i] = max;
2246
6.48k
                    break;
2247
6.48k
                }
2248
23.1k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
23.1k
            } while (i < pal_sz);
2250
12.7k
        }
2251
2252
        // merge cache+new entries
2253
13.8k
        int n = 0, m = n_used_cache;
2254
78.7k
        for (i = 0; i < pal_sz; i++) {
2255
64.8k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
9.40k
                pal[i] = used_cache[n++];
2257
55.4k
            } else {
2258
55.4k
                assert(m < pal_sz);
2259
55.4k
                pal[i] = pal[m++];
2260
55.4k
            }
2261
64.8k
        }
2262
13.8k
    } else {
2263
1.78k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.78k
    }
2265
2266
15.6k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
15.6k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
7.76k
{
2176
7.76k
    Dav1dTileState *const ts = t->ts;
2177
7.76k
    const Dav1dFrameContext *const f = t->f;
2178
7.76k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
7.76k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
7.76k
    pixel cache[16], used_cache[8];
2181
7.76k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
7.76k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
7.76k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
7.76k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
7.76k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
12.5k
    while (l_cache && a_cache) {
2190
4.82k
        if (*l < *a) {
2191
1.73k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
1.71k
                cache[n_cache++] = *l;
2193
1.73k
            l++;
2194
1.73k
            l_cache--;
2195
3.09k
        } else {
2196
3.09k
            if (*a == *l) {
2197
1.19k
                l++;
2198
1.19k
                l_cache--;
2199
1.19k
            }
2200
3.09k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
2.96k
                cache[n_cache++] = *a;
2202
3.09k
            a++;
2203
3.09k
            a_cache--;
2204
3.09k
        }
2205
4.82k
    }
2206
7.76k
    if (l_cache) {
2207
9.05k
        do {
2208
9.05k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
6.99k
                cache[n_cache++] = *l;
2210
9.05k
            l++;
2211
9.05k
        } while (--l_cache > 0);
2212
5.76k
    } else if (a_cache) {
2213
5.98k
        do {
2214
5.98k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
4.95k
                cache[n_cache++] = *a;
2216
5.98k
            a++;
2217
5.98k
        } while (--a_cache > 0);
2218
1.45k
    }
2219
2220
    // find reused cache entries
2221
7.76k
    int i = 0;
2222
22.5k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
14.7k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
7.12k
            used_cache[i++] = cache[n];
2225
7.76k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
7.76k
    pixel *const pal = t->frame_thread.pass ?
2229
7.76k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
7.76k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
7.76k
        bytefn(t->scratch.pal)[pl];
2232
7.76k
    if (i < pal_sz) {
2233
6.87k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
6.87k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
6.87k
        if (i < pal_sz) {
2237
6.31k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
6.31k
            const int max = (1 << bpc) - 1;
2239
2240
15.2k
            do {
2241
15.2k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
15.2k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
15.2k
                if (prev + !pl >= max) {
2244
9.05k
                    for (; i < pal_sz; i++)
2245
5.90k
                        pal[i] = max;
2246
3.15k
                    break;
2247
3.15k
                }
2248
12.1k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
12.1k
            } while (i < pal_sz);
2250
6.31k
        }
2251
2252
        // merge cache+new entries
2253
6.87k
        int n = 0, m = n_used_cache;
2254
39.5k
        for (i = 0; i < pal_sz; i++) {
2255
32.7k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
4.66k
                pal[i] = used_cache[n++];
2257
28.0k
            } else {
2258
28.0k
                assert(m < pal_sz);
2259
28.0k
                pal[i] = pal[m++];
2260
28.0k
            }
2261
32.7k
        }
2262
6.87k
    } else {
2263
895
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
895
    }
2265
2266
7.76k
    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.76k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
7.87k
{
2176
7.87k
    Dav1dTileState *const ts = t->ts;
2177
7.87k
    const Dav1dFrameContext *const f = t->f;
2178
7.87k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
7.87k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
7.87k
    pixel cache[16], used_cache[8];
2181
7.87k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
7.87k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
7.87k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
7.87k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
7.87k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
13.3k
    while (l_cache && a_cache) {
2190
5.44k
        if (*l < *a) {
2191
1.91k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
1.89k
                cache[n_cache++] = *l;
2193
1.91k
            l++;
2194
1.91k
            l_cache--;
2195
3.53k
        } else {
2196
3.53k
            if (*a == *l) {
2197
1.41k
                l++;
2198
1.41k
                l_cache--;
2199
1.41k
            }
2200
3.53k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
3.32k
                cache[n_cache++] = *a;
2202
3.53k
            a++;
2203
3.53k
            a_cache--;
2204
3.53k
        }
2205
5.44k
    }
2206
7.87k
    if (l_cache) {
2207
8.55k
        do {
2208
8.55k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
6.80k
                cache[n_cache++] = *l;
2210
8.55k
            l++;
2211
8.55k
        } while (--l_cache > 0);
2212
5.85k
    } else if (a_cache) {
2213
5.80k
        do {
2214
5.80k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
4.54k
                cache[n_cache++] = *a;
2216
5.80k
            a++;
2217
5.80k
        } while (--a_cache > 0);
2218
1.44k
    }
2219
2220
    // find reused cache entries
2221
7.87k
    int i = 0;
2222
22.7k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
14.8k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
7.27k
            used_cache[i++] = cache[n];
2225
7.87k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
7.87k
    pixel *const pal = t->frame_thread.pass ?
2229
7.87k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
7.87k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
7.87k
        bytefn(t->scratch.pal)[pl];
2232
7.87k
    if (i < pal_sz) {
2233
6.98k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
6.98k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
6.98k
        if (i < pal_sz) {
2237
6.46k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
6.46k
            const int max = (1 << bpc) - 1;
2239
2240
14.3k
            do {
2241
14.3k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
14.3k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
14.3k
                if (prev + !pl >= max) {
2244
9.40k
                    for (; i < pal_sz; i++)
2245
6.06k
                        pal[i] = max;
2246
3.33k
                    break;
2247
3.33k
                }
2248
11.0k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
11.0k
            } while (i < pal_sz);
2250
6.46k
        }
2251
2252
        // merge cache+new entries
2253
6.98k
        int n = 0, m = n_used_cache;
2254
39.1k
        for (i = 0; i < pal_sz; i++) {
2255
32.1k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
4.73k
                pal[i] = used_cache[n++];
2257
27.3k
            } else {
2258
27.3k
                assert(m < pal_sz);
2259
27.3k
                pal[i] = pal[m++];
2260
27.3k
            }
2261
32.1k
        }
2262
6.98k
    } else {
2263
886
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
886
    }
2265
2266
7.87k
    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.87k
}
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
3.89k
{
2281
3.89k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
3.89k
    Dav1dTileState *const ts = t->ts;
2285
3.89k
    const Dav1dFrameContext *const f = t->f;
2286
3.89k
    pixel *const pal = t->frame_thread.pass ?
2287
3.89k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
3.89k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
3.89k
        bytefn(t->scratch.pal)[2];
2290
3.89k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
3.89k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.05k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.05k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.05k
        const int max = (1 << bpc) - 1;
2295
8.86k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
6.80k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
6.80k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
6.80k
            prev = pal[i] = (prev + delta) & max;
2299
6.80k
        }
2300
2.05k
    } else {
2301
10.0k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
8.19k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.83k
    }
2304
3.89k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
3.89k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
2.01k
{
2281
2.01k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
2.01k
    Dav1dTileState *const ts = t->ts;
2285
2.01k
    const Dav1dFrameContext *const f = t->f;
2286
2.01k
    pixel *const pal = t->frame_thread.pass ?
2287
2.01k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
2.01k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
2.01k
        bytefn(t->scratch.pal)[2];
2290
2.01k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
2.01k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.06k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.06k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.06k
        const int max = (1 << bpc) - 1;
2295
4.67k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
3.60k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
3.60k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
3.60k
            prev = pal[i] = (prev + delta) & max;
2299
3.60k
        }
2300
1.06k
    } else {
2301
5.16k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
4.20k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
953
    }
2304
2.01k
    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.01k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
1.87k
{
2281
1.87k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
1.87k
    Dav1dTileState *const ts = t->ts;
2285
1.87k
    const Dav1dFrameContext *const f = t->f;
2286
1.87k
    pixel *const pal = t->frame_thread.pass ?
2287
1.87k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
1.87k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
1.87k
        bytefn(t->scratch.pal)[2];
2290
1.87k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
1.87k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
988
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
988
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
988
        const int max = (1 << bpc) - 1;
2295
4.19k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
3.20k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
3.20k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
3.20k
            prev = pal[i] = (prev + delta) & max;
2299
3.20k
        }
2300
988
    } else {
2301
4.87k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
3.99k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
884
    }
2304
1.87k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
1.87k
}