Coverage Report

Created: 2026-09-01 06:56

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
684k
static inline unsigned read_golomb(MsacContext *const msac) {
50
684k
    int len = 0;
51
684k
    unsigned val = 1;
52
53
1.29M
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
1.29M
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
684k
    return val - 1;
57
684k
}
58
59
static inline unsigned get_skip_ctx(const TxfmInfo *const t_dim,
60
                                    const enum BlockSize bs,
61
                                    const uint8_t *const a,
62
                                    const uint8_t *const l,
63
                                    const int chroma,
64
                                    const enum Dav1dPixelLayout layout)
65
4.72M
{
66
4.72M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
4.72M
    if (chroma) {
69
2.53M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
2.53M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
2.53M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
1.44M
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
2.53M
        unsigned ca, cl;
74
75
2.53M
#define MERGE_CTX(dir, type, no_val) \
76
5.07M
        c##dir = *(const type *) dir != no_val; \
77
5.07M
        break
78
79
2.53M
        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
1.08M
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
485k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
374k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
591k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
2.53M
        }
91
2.53M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
1.20M
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
473k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
294k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
568k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
2.53M
        }
98
2.53M
#undef MERGE_CTX
99
100
2.53M
        return 7 + not_one_blk * 3 + ca + cl;
101
2.53M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
723k
        return 0;
103
1.46M
    } else {
104
1.46M
        unsigned la, ll;
105
106
1.46M
#define MERGE_CTX(dir, type, tx) \
107
2.96M
        if (tx == TX_64X64) { \
108
159k
            uint64_t tmp = *(const uint64_t *) dir; \
109
159k
            tmp |= *(const uint64_t *) &dir[8]; \
110
159k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
159k
        } else \
112
2.96M
            l##dir = *(const type *) dir; \
113
2.96M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
2.96M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
2.96M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
2.96M
        break
117
118
1.46M
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
869k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
280k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
231k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
18.8k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
79.9k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
1.46M
        }
126
1.48M
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
877k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
274k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
230k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
18.4k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
79.9k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
1.48M
        }
134
1.48M
#undef MERGE_CTX
135
136
1.48M
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
1.48M
    }
138
4.72M
}
139
140
static inline unsigned get_dc_sign_ctx(const int /*enum RectTxfmSize*/ tx,
141
                                       const uint8_t *const a,
142
                                       const uint8_t *const l)
143
2.07M
{
144
2.07M
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
2.07M
    int s;
146
147
2.07M
#if ARCH_X86_64 && defined(__GNUC__)
148
    /* Coerce compilers into producing better code. For some reason
149
     * every x86-64 compiler is awful at handling 64-bit constants. */
150
2.07M
    __asm__("" : "+r"(mask), "+r"(mul));
151
2.07M
#endif
152
153
2.07M
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
986k
    case TX_4X4: {
156
986k
        int t = *(const uint8_t *) a >> 6;
157
986k
        t    += *(const uint8_t *) l >> 6;
158
986k
        s = t - 1 - 1;
159
986k
        break;
160
0
    }
161
211k
    case TX_8X8: {
162
211k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
211k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
211k
        t *= 0x04040404U;
165
211k
        s = (int) (t >> 24) - 2 - 2;
166
211k
        break;
167
0
    }
168
175k
    case TX_16X16: {
169
175k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
175k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
175k
        t *= (uint32_t) mul;
172
175k
        s = (int) (t >> 24) - 4 - 4;
173
175k
        break;
174
0
    }
175
141k
    case TX_32X32: {
176
141k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
141k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
141k
        t *= mul;
179
141k
        s = (int) (t >> 56) - 8 - 8;
180
141k
        break;
181
0
    }
182
64.7k
    case TX_64X64: {
183
64.7k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
64.7k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
64.7k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
64.7k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
64.7k
        t *= mul;
188
64.7k
        s = (int) (t >> 56) - 16 - 16;
189
64.7k
        break;
190
0
    }
191
53.8k
    case RTX_4X8: {
192
53.8k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
53.8k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
53.8k
        t *= 0x04040404U;
195
53.8k
        s = (int) (t >> 24) - 1 - 2;
196
53.8k
        break;
197
0
    }
198
80.3k
    case RTX_8X4: {
199
80.3k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
80.3k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
80.3k
        t *= 0x04040404U;
202
80.3k
        s = (int) (t >> 24) - 2 - 1;
203
80.3k
        break;
204
0
    }
205
52.4k
    case RTX_8X16: {
206
52.4k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
52.4k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
52.4k
        t = (t >> 6) * (uint32_t) mul;
209
52.4k
        s = (int) (t >> 24) - 2 - 4;
210
52.4k
        break;
211
0
    }
212
87.6k
    case RTX_16X8: {
213
87.6k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
87.6k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
87.6k
        t = (t >> 6) * (uint32_t) mul;
216
87.6k
        s = (int) (t >> 24) - 4 - 2;
217
87.6k
        break;
218
0
    }
219
25.7k
    case RTX_16X32: {
220
25.7k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
25.7k
        t         += *(const uint64_t *) l & mask;
222
25.7k
        t = (t >> 6) * mul;
223
25.7k
        s = (int) (t >> 56) - 4 - 8;
224
25.7k
        break;
225
0
    }
226
35.6k
    case RTX_32X16: {
227
35.6k
        uint64_t t = *(const uint64_t *) a & mask;
228
35.6k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
35.6k
        t = (t >> 6) * mul;
230
35.6k
        s = (int) (t >> 56) - 8 - 4;
231
35.6k
        break;
232
0
    }
233
10.1k
    case RTX_32X64: {
234
10.1k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
10.1k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
10.1k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
10.1k
        t *= mul;
238
10.1k
        s = (int) (t >> 56) - 8 - 16;
239
10.1k
        break;
240
0
    }
241
9.45k
    case RTX_64X32: {
242
9.45k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
9.45k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
9.45k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
9.45k
        t *= mul;
246
9.45k
        s = (int) (t >> 56) - 16 - 8;
247
9.45k
        break;
248
0
    }
249
24.8k
    case RTX_4X16: {
250
24.8k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
24.8k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
24.8k
        t = (t >> 6) * (uint32_t) mul;
253
24.8k
        s = (int) (t >> 24) - 1 - 4;
254
24.8k
        break;
255
0
    }
256
55.2k
    case RTX_16X4: {
257
55.2k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
55.2k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
55.2k
        t = (t >> 6) * (uint32_t) mul;
260
55.2k
        s = (int) (t >> 24) - 4 - 1;
261
55.2k
        break;
262
0
    }
263
19.5k
    case RTX_8X32: {
264
19.5k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
19.5k
        t         += *(const uint64_t *) l & mask;
266
19.5k
        t = (t >> 6) * mul;
267
19.5k
        s = (int) (t >> 56) - 2 - 8;
268
19.5k
        break;
269
0
    }
270
28.5k
    case RTX_32X8: {
271
28.5k
        uint64_t t = *(const uint64_t *) a & mask;
272
28.5k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
28.5k
        t = (t >> 6) * mul;
274
28.5k
        s = (int) (t >> 56) - 8 - 2;
275
28.5k
        break;
276
0
    }
277
7.10k
    case RTX_16X64: {
278
7.10k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
7.10k
        t         += *(const uint64_t *) &l[0] & mask;
280
7.10k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
7.10k
        t *= mul;
282
7.10k
        s = (int) (t >> 56) - 4 - 16;
283
7.10k
        break;
284
0
    }
285
3.91k
    case RTX_64X16: {
286
3.91k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
3.91k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
3.91k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
3.91k
        t *= mul;
290
3.91k
        s = (int) (t >> 56) - 16 - 4;
291
3.91k
        break;
292
0
    }
293
2.07M
    }
294
295
2.07M
    return (s != 0) + (s > 0);
296
2.07M
}
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
32.9M
{
305
32.9M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
32.9M
    unsigned offset;
307
32.9M
    if (tx_class == TX_CLASS_2D) {
308
30.3M
        mag += levels[1 * stride + 1];
309
30.3M
        *hi_mag = mag;
310
30.3M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
30.3M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
30.3M
    } else {
313
2.66M
        mag += levels[0 * stride + 2];
314
2.66M
        *hi_mag = mag;
315
2.66M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
2.66M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
2.66M
    }
318
32.9M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
32.9M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
4.72M
{
328
4.72M
    Dav1dTileState *const ts = t->ts;
329
4.72M
    const int chroma = !!plane;
330
4.72M
    const Dav1dFrameContext *const f = t->f;
331
4.72M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
4.72M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
4.72M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
4.72M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
4.72M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
4.72M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
4.72M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
4.72M
    if (dbg)
343
0
        printf("Post-non-zero[%d][%d][%d]: r=%d\n",
344
0
               t_dim->ctx, sctx, all_skip, ts->msac.rng);
345
4.72M
    if (all_skip) {
346
2.28M
        *res_ctx = 0x40;
347
2.28M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
2.28M
        return -1;
349
2.28M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
2.44M
    if (lossless) {
353
917k
        assert(t_dim->max == TX_4X4);
354
917k
        *txtp = WHT_WHT;
355
1.52M
    } else if (t_dim->max + intra >= TX_64X64) {
356
292k
        *txtp = DCT_DCT;
357
1.23M
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
336k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
336k
                        get_uv_inter_txtp(t_dim, *txtp);
361
894k
    } 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
4.68k
        *txtp = DCT_DCT;
366
889k
    } else {
367
889k
        unsigned idx;
368
889k
        if (intra) {
369
520k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
456k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
520k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
259k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
259k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
259k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
261k
            } else {
376
261k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
261k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
261k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
261k
            }
380
520k
            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
520k
        } else {
384
368k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
91.4k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
91.4k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
91.4k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
277k
            } else if (t_dim->min == TX_16X16) {
389
34.8k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
34.8k
                          ts->cdf.m.txtp_inter2, 11);
391
34.8k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
242k
            } else {
393
242k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
242k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
242k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
242k
            }
397
368k
            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
368k
        }
401
889k
    }
402
403
    // find end-of-block (eob)
404
2.44M
    int eob;
405
2.44M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
2.44M
    const int tx2dszctx = slw + slh;
407
2.44M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
2.44M
    const int is_1d = tx_class != TX_CLASS_2D;
409
2.44M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
2.45M
    case sz: { \
412
2.45M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
2.45M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
2.45M
        break; \
415
2.45M
    }
416
1.09M
    case_sz(0,   16,  8, [is_1d]);
417
180k
    case_sz(1,   32,  8, [is_1d]);
418
382k
    case_sz(2,   64,  8, [is_1d]);
419
185k
    case_sz(3,  128,  8, [is_1d]);
420
276k
    case_sz(4,  256, 16, [is_1d]);
421
83.7k
    case_sz(5,  512, 16,        );
422
246k
    case_sz(6, 1024, 16,        );
423
2.44M
#undef case_sz
424
2.44M
    }
425
2.44M
    if (dbg)
426
0
        printf("Post-eob_bin_%d[%d][%d][%d]: r=%d\n",
427
0
               16 << tx2dszctx, chroma, is_1d, eob, ts->msac.rng);
428
2.44M
    if (eob > 1) {
429
1.31M
        const int eob_bin = eob - 2;
430
1.31M
        uint16_t *const eob_hi_bit_cdf =
431
1.31M
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
1.31M
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
1.31M
        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.31M
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
1.31M
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
1.31M
    }
440
2.44M
    assert(eob >= 0);
441
442
    // base tokens
443
2.44M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
2.44M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
2.44M
    unsigned rc, dc_tok;
446
447
2.44M
    if (eob) {
448
1.39M
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
1.39M
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
1.39M
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
1.39M
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
1.39M
        int tok = eob_tok + 1;
455
1.39M
        int level_tok = tok * 0x41;
456
1.39M
        unsigned mag;
457
458
1.39M
#define DECODE_COEFS_CLASS(tx_class) \
459
1.39M
        unsigned x, y; \
460
1.39M
        uint8_t *level; \
461
1.39M
        if (tx_class == TX_CLASS_2D) \
462
1.39M
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
1.39M
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
152k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
152k
        else /* tx_class == TX_CLASS_V */ \
467
152k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
1.39M
        if (dbg) \
469
1.39M
            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.39M
        if (eob_tok == 2) { \
472
26.7k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
26.7k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
26.7k
            level_tok = tok + (3 << 6); \
475
26.7k
            if (dbg) \
476
26.7k
                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
26.7k
        } \
480
1.39M
        cf[rc] = tok << 11; \
481
1.39M
        if (tx_class == TX_CLASS_2D) \
482
1.39M
            level = levels + rc; \
483
1.39M
        else \
484
1.39M
            level = levels + x * stride + y; \
485
1.39M
        *level = (uint8_t) level_tok; \
486
34.2M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
32.8M
            unsigned rc_i; \
488
32.8M
            if (tx_class == TX_CLASS_2D) \
489
32.8M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
32.8M
            else if (tx_class == TX_CLASS_H) \
491
2.54M
                x = i & mask, y = i >> shift, rc_i = i; \
492
2.54M
            else /* tx_class == TX_CLASS_V */ \
493
2.54M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
32.8M
            assert(x < 32 && y < 32); \
495
32.8M
            if (tx_class == TX_CLASS_2D) \
496
32.8M
                level = levels + rc_i; \
497
32.8M
            else \
498
32.8M
                level = levels + x * stride + y; \
499
32.8M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
32.8M
            if (tx_class == TX_CLASS_2D) \
501
32.8M
                y |= x; \
502
32.8M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
32.8M
            if (dbg) \
504
32.8M
                printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
505
0
                       t_dim->ctx, chroma, ctx, i, rc_i, tok, ts->msac.rng); \
506
32.8M
            if (tok == 3) { \
507
2.60M
                mag &= 63; \
508
2.60M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
2.60M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
2.60M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
2.60M
                if (dbg) \
512
2.60M
                    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.60M
                *level = (uint8_t) (tok + (3 << 6)); \
516
2.60M
                cf[rc_i] = (tok << 11) | rc; \
517
2.60M
                rc = rc_i; \
518
30.2M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
30.2M
                tok *= 0x17ff41; \
521
30.2M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
30.2M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
30.2M
                if (tok) rc = rc_i; \
525
30.2M
                cf[rc_i] = tok; \
526
30.2M
            } \
527
32.8M
        } \
528
        /* dc */ \
529
1.39M
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
1.39M
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
1.39M
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
1.39M
        if (dbg) \
533
1.39M
            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.39M
        if (dc_tok == 3) { \
536
468k
            if (tx_class == TX_CLASS_2D) \
537
468k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
456k
                      levels[1 * stride + 1]; \
539
468k
            mag &= 63; \
540
468k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
468k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
468k
            if (dbg) \
543
468k
                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
468k
        } \
546
1.39M
        break
547
548
1.39M
        const uint16_t *scan;
549
1.39M
        switch (tx_class) {
550
1.24M
        case TX_CLASS_2D: {
551
1.24M
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
1.24M
            const uint8_t (*const lo_ctx_offsets)[5] =
553
1.24M
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
1.24M
            scan = dav1d_scans[tx];
555
1.24M
            const ptrdiff_t stride = 4 << slh;
556
1.24M
            const unsigned shift = slh + 2, shift2 = 0;
557
1.24M
            const unsigned mask = (4 << slh) - 1;
558
1.24M
            memset(levels, 0, stride * ((4 << slw) + 2));
559
1.24M
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
1.24M
        }
561
97.7k
        case TX_CLASS_H: {
562
97.7k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
97.7k
            const ptrdiff_t stride = 16;
564
97.7k
            const unsigned shift = slh + 2, shift2 = 0;
565
97.7k
            const unsigned mask = (4 << slh) - 1;
566
97.7k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
97.7k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
97.7k
        }
569
54.7k
        case TX_CLASS_V: {
570
54.7k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
54.7k
            const ptrdiff_t stride = 16;
572
54.7k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
54.7k
            const unsigned mask = (4 << slw) - 1;
574
54.7k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
54.7k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
54.7k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
1.39M
        }
580
1.39M
    } else { // dc-only
581
1.05M
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
1.05M
        dc_tok = 1 + tok_br;
583
1.05M
        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
1.05M
        if (tok_br == 2) {
587
30.4k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
30.4k
            if (dbg)
589
0
                printf("Post-dc_hi_tok[%d][%d][0][%d]: r=%d\n",
590
0
                       imin(t_dim->ctx, 3), chroma, dc_tok, ts->msac.rng);
591
30.4k
        }
592
1.05M
        rc = 0;
593
1.05M
    }
594
595
    // residual and sign
596
2.44M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
2.44M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
2.44M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
2.44M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
2.44M
    unsigned cul_level, dc_sign_level;
601
602
2.44M
    if (!dc_tok) {
603
376k
        cul_level = 0;
604
376k
        dc_sign_level = 1 << 6;
605
376k
        if (qm_tbl) goto ac_qm;
606
246k
        goto ac_noqm;
607
376k
    }
608
609
2.07M
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
2.07M
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
2.07M
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
2.07M
    if (dbg)
613
0
        printf("Post-dc_sign[%d][%d][%d]: r=%d\n",
614
0
               chroma, dc_sign_ctx, dc_sign, ts->msac.rng);
615
616
2.07M
    int dc_dq = dq_tbl[0];
617
2.07M
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
2.07M
    if (qm_tbl) {
620
701k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
701k
        if (dc_tok == 15) {
623
13.6k
            dc_tok = read_golomb(&ts->msac) + 15;
624
13.6k
            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
13.6k
            dc_tok &= 0xfffff;
629
13.6k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
687k
        } else {
631
687k
            dc_dq *= dc_tok;
632
687k
            assert(dc_dq <= 0xffffff);
633
687k
        }
634
701k
        cul_level = dc_tok;
635
701k
        dc_dq >>= dq_shift;
636
701k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
701k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
980k
        if (rc) ac_qm: {
640
980k
            const unsigned ac_dq = dq_tbl[1];
641
6.28M
            do {
642
6.28M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
6.28M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
6.28M
                const unsigned rc_tok = cf[rc];
646
6.28M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
6.28M
                int dq_sat;
648
649
6.28M
                if (rc_tok >= (15 << 11)) {
650
525k
                    tok = read_golomb(&ts->msac) + 15;
651
525k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
525k
                    tok &= 0xfffff;
656
525k
                    dq = (dq * tok) & 0xffffff;
657
5.75M
                } else {
658
5.75M
                    tok = rc_tok >> 11;
659
5.75M
                    dq *= tok;
660
5.75M
                    assert(dq <= 0xffffff);
661
5.75M
                }
662
6.28M
                cul_level += tok;
663
6.28M
                dq >>= dq_shift;
664
6.28M
                dq_sat = umin(dq, cf_max + sign);
665
6.28M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
6.28M
                rc = rc_tok & 0x3ff;
668
6.28M
            } while (rc);
669
980k
        }
670
1.37M
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
1.37M
        if (dc_tok == 15) {
673
29.0k
            dc_tok = read_golomb(&ts->msac) + 15;
674
29.0k
            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
29.0k
            dc_tok &= 0xfffff;
679
29.0k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
29.0k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
1.34M
        } else {
682
1.34M
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
1.34M
            assert(dc_dq <= cf_max);
684
1.34M
        }
685
1.37M
        cul_level = dc_tok;
686
1.37M
        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.23M
            do {
691
6.23M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
6.23M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
6.23M
                const unsigned rc_tok = cf[rc];
695
6.23M
                unsigned tok;
696
6.23M
                int dq;
697
698
                // residual
699
6.23M
                if (rc_tok >= (15 << 11)) {
700
116k
                    tok = read_golomb(&ts->msac) + 15;
701
116k
                    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
116k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
116k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
116k
                    dq = umin(dq, cf_max + sign);
711
6.11M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
6.11M
                    tok = rc_tok >> 11;
714
6.11M
                    dq = ((ac_dq * tok) >> dq_shift);
715
6.11M
                    assert(dq <= cf_max);
716
6.11M
                }
717
6.23M
                cul_level += tok;
718
6.23M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
6.23M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
6.23M
            } while (rc);
722
1.43M
        }
723
1.37M
    }
724
725
    // context
726
2.44M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
2.44M
    return eob;
729
2.07M
}
730
731
static void read_coef_tree(Dav1dTaskContext *const t,
732
                           const enum BlockSize bs, const Av1Block *const b,
733
                           const enum RectTxfmSize ytx, const int depth,
734
                           const uint16_t *const tx_split,
735
                           const int x_off, const int y_off, pixel *dst)
736
1.17M
{
737
1.17M
    const Dav1dFrameContext *const f = t->f;
738
1.17M
    Dav1dTileState *const ts = t->ts;
739
1.17M
    const Dav1dDSPContext *const dsp = f->dsp;
740
1.17M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
1.17M
    const int txw = t_dim->w, txh = t_dim->h;
742
743
    /* y_off can be larger than 3 since lossless blocks use TX_4X4 but can't
744
     * be splitted. Aviods an undefined left shift. */
745
1.17M
    if (depth < 2 && tx_split[depth] &&
746
111k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
87.2k
    {
748
87.2k
        const enum RectTxfmSize sub = t_dim->sub;
749
87.2k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
87.2k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
87.2k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
87.2k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
87.2k
        t->bx += txsw;
755
87.2k
        if (txw >= txh && t->bx < f->bw)
756
67.6k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
67.6k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
87.2k
        t->bx -= txsw;
759
87.2k
        t->by += txsh;
760
87.2k
        if (txh >= txw && t->by < f->bh) {
761
61.7k
            if (dst)
762
21.7k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
61.7k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
61.7k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
61.7k
            t->bx += txsw;
766
61.7k
            if (txw >= txh && t->bx < f->bw)
767
42.9k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
42.9k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
61.7k
            t->bx -= txsw;
770
61.7k
        }
771
87.2k
        t->by -= txsh;
772
1.08M
    } else {
773
1.08M
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
1.08M
        enum TxfmType txtp;
775
1.08M
        uint8_t cf_ctx;
776
1.08M
        int eob;
777
1.08M
        coef *cf;
778
779
1.08M
        if (t->frame_thread.pass) {
780
1.08M
            const int p = t->frame_thread.pass & 1;
781
1.08M
            assert(ts->frame_thread[p].cf);
782
1.08M
            cf = ts->frame_thread[p].cf;
783
1.08M
            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
784
18.4E
        } else {
785
18.4E
            cf = bitfn(t->cf);
786
18.4E
        }
787
1.08M
        if (t->frame_thread.pass != 2) {
788
735k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
735k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
735k
            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
735k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
735k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
735k
#define set_ctx(rep_macro) \
796
2.70M
            for (int y = 0; y < txh; y++) { \
797
1.96M
                rep_macro(txtp_map, 0, txtp); \
798
1.96M
                txtp_map += 32; \
799
1.96M
            }
800
735k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
735k
            case_set_upto16(t_dim->lw);
802
735k
#undef set_ctx
803
735k
            if (t->frame_thread.pass == 1)
804
735k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
735k
        } else {
806
354k
            const int cbi = *ts->frame_thread[0].cbi++;
807
354k
            eob  = cbi >> 5;
808
354k
            txtp = cbi & 0x1f;
809
354k
        }
810
1.08M
        if (!(t->frame_thread.pass & 1)) {
811
355k
            assert(dst);
812
355k
            if (eob >= 0) {
813
235k
                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
235k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
235k
                                              HIGHBD_CALL_SUFFIX);
817
235k
                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
235k
            }
820
355k
        }
821
1.08M
    }
822
1.17M
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
2.35M
{
827
2.35M
    const Dav1dFrameContext *const f = t->f;
828
2.35M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
2.35M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
2.35M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
2.35M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
2.35M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
2.35M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
2.35M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
2.35M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
2.02M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.91M
                           (bh4 > ss_ver || t->by & 1);
838
839
2.35M
    if (b->skip) {
840
1.44M
        BlockContext *const a = t->a;
841
1.44M
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
1.44M
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
1.44M
        if (has_chroma) {
844
1.04M
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
1.04M
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
1.04M
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
1.04M
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
1.04M
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
1.04M
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
1.04M
        }
851
1.44M
        return;
852
1.44M
    }
853
854
906k
    Dav1dTileState *const ts = t->ts;
855
906k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
906k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
906k
    assert(t->frame_thread.pass == 1);
858
906k
    assert(!b->skip);
859
906k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
906k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
906k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.84M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
934k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.90M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
969k
            const int sub_w4 = imin(w4, init_x + 16);
867
969k
            int y_off = !!init_y, y, x;
868
2.13M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
1.16M
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
1.16M
            {
871
1.16M
                int x_off = !!init_x;
872
3.25M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
2.09M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
2.09M
                {
875
2.09M
                    if (!b->intra) {
876
622k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
622k
                                       x_off, y_off, NULL);
878
1.46M
                    } else {
879
1.46M
                        uint8_t cf_ctx = 0x40;
880
1.46M
                        enum TxfmType txtp;
881
1.46M
                        const int eob =
882
1.46M
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
1.46M
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
1.46M
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
1.46M
                        if (DEBUG_BLOCK_INFO)
886
0
                            printf("Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n",
887
0
                                   b->tx, txtp, eob, ts->msac.rng);
888
1.46M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
1.46M
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
1.46M
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
1.46M
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
1.46M
                    }
893
2.09M
                }
894
1.16M
                t->bx -= x;
895
1.16M
            }
896
969k
            t->by -= y;
897
898
969k
            if (!has_chroma) continue;
899
900
818k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
818k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
2.45M
            for (int pl = 0; pl < 2; pl++) {
903
3.46M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.82M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.82M
                {
906
4.36M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
2.53M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
2.53M
                    {
909
2.53M
                        uint8_t cf_ctx = 0x40;
910
2.53M
                        enum TxfmType txtp;
911
2.53M
                        if (!b->intra)
912
1.22M
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
1.22M
                                                        bx4 + (x << ss_hor)];
914
2.53M
                        const int eob =
915
2.53M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
2.53M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
2.53M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
2.53M
                                         &txtp, &cf_ctx);
919
2.53M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
2.53M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
2.53M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
2.53M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
2.53M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
2.53M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
2.53M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
2.53M
                    }
930
1.82M
                    t->bx -= x << ss_hor;
931
1.82M
                }
932
1.63M
                t->by -= y << ss_ver;
933
1.63M
            }
934
818k
        }
935
934k
    }
936
906k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
1.11M
{
827
1.11M
    const Dav1dFrameContext *const f = t->f;
828
1.11M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.11M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.11M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.11M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.11M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.11M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.11M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.11M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
926k
                           (bw4 > ss_hor || t->bx & 1) &&
837
874k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.11M
    if (b->skip) {
840
701k
        BlockContext *const a = t->a;
841
701k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
701k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
701k
        if (has_chroma) {
844
490k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
490k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
490k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
490k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
490k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
490k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
490k
        }
851
701k
        return;
852
701k
    }
853
854
415k
    Dav1dTileState *const ts = t->ts;
855
415k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
415k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
415k
    assert(t->frame_thread.pass == 1);
858
415k
    assert(!b->skip);
859
415k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
415k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
415k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
842k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
426k
        const int sub_h4 = imin(h4, 16 + init_y);
865
864k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
438k
            const int sub_w4 = imin(w4, init_x + 16);
867
438k
            int y_off = !!init_y, y, x;
868
940k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
502k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
502k
            {
871
502k
                int x_off = !!init_x;
872
1.27M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
775k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
775k
                {
875
775k
                    if (!b->intra) {
876
223k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
223k
                                       x_off, y_off, NULL);
878
552k
                    } else {
879
552k
                        uint8_t cf_ctx = 0x40;
880
552k
                        enum TxfmType txtp;
881
552k
                        const int eob =
882
552k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
552k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
552k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
552k
                        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
552k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
552k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
552k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
552k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
552k
                    }
893
775k
                }
894
502k
                t->bx -= x;
895
502k
            }
896
438k
            t->by -= y;
897
898
438k
            if (!has_chroma) continue;
899
900
356k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
356k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.06M
            for (int pl = 0; pl < 2; pl++) {
903
1.47M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
763k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
763k
                {
906
1.67M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
911k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
911k
                    {
909
911k
                        uint8_t cf_ctx = 0x40;
910
911k
                        enum TxfmType txtp;
911
911k
                        if (!b->intra)
912
439k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
439k
                                                        bx4 + (x << ss_hor)];
914
911k
                        const int eob =
915
911k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
911k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
911k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
911k
                                         &txtp, &cf_ctx);
919
911k
                        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
911k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
911k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
911k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
911k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
911k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
911k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
911k
                    }
930
763k
                    t->bx -= x << ss_hor;
931
763k
                }
932
712k
                t->by -= y << ss_ver;
933
712k
            }
934
356k
        }
935
426k
    }
936
415k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
1.23M
{
827
1.23M
    const Dav1dFrameContext *const f = t->f;
828
1.23M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.23M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.23M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.23M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.23M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.23M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.23M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.23M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.10M
                           (bw4 > ss_hor || t->bx & 1) &&
837
1.04M
                           (bh4 > ss_ver || t->by & 1);
838
839
1.23M
    if (b->skip) {
840
741k
        BlockContext *const a = t->a;
841
741k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
741k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
741k
        if (has_chroma) {
844
559k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
559k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
559k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
559k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
559k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
559k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
559k
        }
851
741k
        return;
852
741k
    }
853
854
491k
    Dav1dTileState *const ts = t->ts;
855
491k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
491k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
491k
    assert(t->frame_thread.pass == 1);
858
491k
    assert(!b->skip);
859
491k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
491k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
491k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
999k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
508k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.04M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
531k
            const int sub_w4 = imin(w4, init_x + 16);
867
531k
            int y_off = !!init_y, y, x;
868
1.19M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
658k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
658k
            {
871
658k
                int x_off = !!init_x;
872
1.97M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
1.31M
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
1.31M
                {
875
1.31M
                    if (!b->intra) {
876
399k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
399k
                                       x_off, y_off, NULL);
878
915k
                    } else {
879
915k
                        uint8_t cf_ctx = 0x40;
880
915k
                        enum TxfmType txtp;
881
915k
                        const int eob =
882
915k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
915k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
915k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
915k
                        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
915k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
915k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
915k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
915k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
915k
                    }
893
1.31M
                }
894
658k
                t->bx -= x;
895
658k
            }
896
531k
            t->by -= y;
897
898
531k
            if (!has_chroma) continue;
899
900
462k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
462k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.38M
            for (int pl = 0; pl < 2; pl++) {
903
1.98M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.06M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.06M
                {
906
2.68M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.62M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.62M
                    {
909
1.62M
                        uint8_t cf_ctx = 0x40;
910
1.62M
                        enum TxfmType txtp;
911
1.62M
                        if (!b->intra)
912
787k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
787k
                                                        bx4 + (x << ss_hor)];
914
1.62M
                        const int eob =
915
1.62M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.62M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.62M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.62M
                                         &txtp, &cf_ctx);
919
1.62M
                        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.62M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.62M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.62M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.62M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.62M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.62M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.62M
                    }
930
1.06M
                    t->bx -= x << ss_hor;
931
1.06M
                }
932
924k
                t->by -= y << ss_ver;
933
924k
            }
934
462k
        }
935
508k
    }
936
491k
}
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
1.58M
{
945
1.58M
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
1.58M
    const Dav1dFrameContext *const f = t->f;
947
1.58M
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
1.58M
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
1.58M
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
1.58M
    const int mvx = mv.x, mvy = mv.y;
951
1.58M
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
1.58M
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
1.58M
    const pixel *ref;
954
955
1.58M
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
376k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
376k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
376k
        int w, h;
959
960
376k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
328k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
328k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
328k
        } else {
964
48.3k
            w = f->bw * 4 >> ss_hor;
965
48.3k
            h = f->bh * 4 >> ss_ver;
966
48.3k
        }
967
376k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
254k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
138k
            dy + bh4 * v_mul + !!my * 4 > h)
970
276k
        {
971
276k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
276k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
276k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
276k
                                emu_edge_buf, 192 * sizeof(pixel),
975
276k
                                refp->p.data[pl], ref_stride);
976
276k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
276k
            ref_stride = 192 * sizeof(pixel);
978
276k
        } else {
979
99.6k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
99.6k
        }
981
982
376k
        if (dst8 != NULL) {
983
282k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
282k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
282k
                                     HIGHBD_CALL_SUFFIX);
986
282k
        } else {
987
93.7k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
93.7k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
93.7k
                                      HIGHBD_CALL_SUFFIX);
990
93.7k
        }
991
1.20M
    } else {
992
1.20M
        assert(refp != &f->sr_cur);
993
994
1.20M
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
1.20M
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
2.40M
#define scale_mv(res, val, scale) do { \
997
2.40M
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
2.40M
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
2.40M
        } while (0)
1000
1.20M
        int pos_y, pos_x;
1001
1.20M
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
1.20M
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
1.20M
#undef scale_mv
1004
1.20M
        const int left = pos_x >> 10;
1005
1.20M
        const int top = pos_y >> 10;
1006
1.20M
        const int right =
1007
1.20M
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
1.20M
        const int bottom =
1009
1.20M
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
1.20M
        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
1.20M
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
1.20M
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
1.20M
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
389k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
389k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
389k
                                w, h, left - 3, top - 3,
1023
389k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
389k
                                refp->p.data[pl], ref_stride);
1025
389k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
389k
            ref_stride = 320 * sizeof(pixel);
1027
389k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
814k
        } else {
1029
814k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
814k
        }
1031
1032
1.20M
        if (dst8 != NULL) {
1033
987k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
987k
                                            bw4 * h_mul, bh4 * v_mul,
1035
987k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
987k
                                            f->svc[refidx][0].step,
1037
987k
                                            f->svc[refidx][1].step
1038
987k
                                            HIGHBD_CALL_SUFFIX);
1039
987k
        } else {
1040
216k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
216k
                                             bw4 * h_mul, bh4 * v_mul,
1042
216k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
216k
                                             f->svc[refidx][0].step,
1044
216k
                                             f->svc[refidx][1].step
1045
216k
                                             HIGHBD_CALL_SUFFIX);
1046
216k
        }
1047
1.20M
    }
1048
1049
1.58M
    return 0;
1050
1.58M
}
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
177k
{
1057
177k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
177k
    const Dav1dFrameContext *const f = t->f;
1059
177k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
177k
    pixel *const lap = bitfn(t->scratch.lap);
1061
177k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
177k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
177k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
177k
    int res;
1065
1066
177k
    if (t->by > t->ts->tiling.row_start &&
1067
151k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
148k
    {
1069
311k
        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
162k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
162k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
162k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
162k
            if (a_r->ref.ref[0] > 0) {
1076
160k
                const int ow4 = imin(step4, b_dim[0]);
1077
160k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
160k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
160k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
160k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
160k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
160k
                if (res) return res;
1083
160k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
160k
                                   h_mul * ow4, v_mul * oh4);
1085
160k
                i++;
1086
160k
            }
1087
162k
            x += step4;
1088
162k
        }
1089
148k
    }
1090
1091
177k
    if (t->bx > t->ts->tiling.col_start)
1092
359k
        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
187k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
187k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
187k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
187k
            if (l_r->ref.ref[0] > 0) {
1099
184k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
184k
                const int oh4 = imin(step4, b_dim[1]);
1101
184k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
184k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
184k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
184k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
184k
                if (res) return res;
1106
184k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
184k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
184k
                i++;
1109
184k
            }
1110
187k
            y += step4;
1111
187k
        }
1112
177k
    return 0;
1113
177k
}
1114
1115
static int warp_affine(Dav1dTaskContext *const t,
1116
                       pixel *dst8, int16_t *dst16, const ptrdiff_t dstride,
1117
                       const uint8_t *const b_dim, const int pl,
1118
                       const Dav1dThreadPicture *const refp,
1119
                       const Dav1dWarpedMotionParams *const wmp)
1120
16.4k
{
1121
16.4k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
16.4k
    const Dav1dFrameContext *const f = t->f;
1123
16.4k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
16.4k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
16.4k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
16.4k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
16.4k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
16.4k
    const int32_t *const mat = wmp->matrix;
1129
16.4k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
16.4k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
61.7k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
45.2k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
45.2k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
45.2k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
234k
        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
189k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
189k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
189k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
189k
            const int dx = (int) (mvx >> 16) - 4;
1144
189k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
189k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
189k
            const int dy = (int) (mvy >> 16) - 4;
1147
189k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
189k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
189k
            const pixel *ref_ptr;
1151
189k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
189k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
168k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
168k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
168k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
168k
                                    refp->p.data[pl], ref_stride);
1158
168k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
168k
                ref_stride = 32 * sizeof(pixel);
1160
168k
            } else {
1161
20.3k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
20.3k
            }
1163
189k
            if (dst16 != NULL)
1164
30.4k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
30.4k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
158k
            else
1167
158k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
158k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
189k
        }
1170
45.2k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
10.5k
        else      dst16 += 8 * dstride;
1172
45.2k
    }
1173
16.4k
    return 0;
1174
16.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
1.04M
{
1180
1.04M
    Dav1dTileState *const ts = t->ts;
1181
1.04M
    const Dav1dFrameContext *const f = t->f;
1182
1.04M
    const Dav1dDSPContext *const dsp = f->dsp;
1183
1.04M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
1.04M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
1.04M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
1.04M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
1.04M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
1.04M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
1.04M
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
1.04M
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
1.04M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
896k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
835k
                           (bh4 > ss_ver || t->by & 1);
1194
1.04M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
1.04M
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
1.04M
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
1.04M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
1.04M
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
2.11M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
1.06M
        const int sub_h4 = imin(h4, 16 + init_y);
1205
1.06M
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
2.16M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
1.10M
            if (b->pal_sz[0]) {
1208
8.09k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
8.09k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
8.09k
                const uint8_t *pal_idx;
1211
8.09k
                if (t->frame_thread.pass) {
1212
8.09k
                    const int p = t->frame_thread.pass & 1;
1213
8.09k
                    assert(ts->frame_thread[p].pal_idx);
1214
8.09k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
8.09k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
8.09k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
8.09k
                const pixel *const pal = t->frame_thread.pass ?
1220
8.09k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
8.09k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
8.09k
                    bytefn(t->scratch.pal)[0];
1223
8.09k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
8.09k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
8.09k
                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
8.09k
            }
1229
1230
1.10M
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
1.10M
                                     sm_flag(&t->l, by4) |
1232
1.10M
                                     intra_edge_filter_flag);
1233
1.10M
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
1.06M
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
1.10M
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
1.06M
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
1.10M
            int y, x;
1238
1.10M
            const int sub_w4 = imin(w4, init_x + 16);
1239
2.48M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
1.38M
                 y += t_dim->h, t->by += t_dim->h)
1241
1.38M
            {
1242
1.38M
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
1.38M
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
1.38M
                                    t->bx + init_x);
1245
3.85M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
2.46M
                     x += t_dim->w, t->bx += t_dim->w)
1247
2.46M
                {
1248
2.46M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
2.45M
                    int angle = b->y_angle;
1251
2.45M
                    const enum EdgeFlags edge_flags =
1252
2.45M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.82M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
2.45M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.70M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
2.45M
                    const pixel *top_sb_edge = NULL;
1257
2.45M
                    if (!(t->by & (f->sb_step - 1))) {
1258
475k
                        top_sb_edge = f->ipred_edge[0];
1259
475k
                        const int sby = t->by >> f->sb_shift;
1260
475k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
475k
                    }
1262
2.45M
                    const enum IntraPredMode m =
1263
2.45M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
2.45M
                                                          t->bx > ts->tiling.col_start,
1265
2.45M
                                                          t->by,
1266
2.45M
                                                          t->by > ts->tiling.row_start,
1267
2.45M
                                                          ts->tiling.col_end,
1268
2.45M
                                                          ts->tiling.row_end,
1269
2.45M
                                                          edge_flags, dst,
1270
2.45M
                                                          f->cur.stride[0], top_sb_edge,
1271
2.45M
                                                          b->y_mode, &angle,
1272
2.45M
                                                          t_dim->w, t_dim->h,
1273
2.45M
                                                          f->seq_hdr->intra_edge_filter,
1274
2.45M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
2.45M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
2.45M
                                             t_dim->w * 4, t_dim->h * 4,
1277
2.45M
                                             angle | intra_flags,
1278
2.45M
                                             4 * f->bw - 4 * t->bx,
1279
2.45M
                                             4 * f->bh - 4 * t->by
1280
2.45M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
2.45M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
2.46M
                skip_y_pred: {}
1293
2.46M
                    if (!b->skip) {
1294
881k
                        coef *cf;
1295
881k
                        int eob;
1296
881k
                        enum TxfmType txtp;
1297
881k
                        if (t->frame_thread.pass) {
1298
881k
                            const int p = t->frame_thread.pass & 1;
1299
881k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
881k
                            cf = ts->frame_thread[p].cf;
1301
881k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
881k
                            eob  = cbi >> 5;
1303
881k
                            txtp = cbi & 0x1f;
1304
881k
                        } 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
881k
                        if (eob >= 0) {
1317
657k
                            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
657k
                            dsp->itx.itxfm_add[b->tx]
1321
657k
                                              [txtp](dst,
1322
657k
                                                     f->cur.stride[0],
1323
657k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
657k
                            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
657k
                        }
1328
1.58M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
2.46M
                    dst += 4 * t_dim->w;
1333
2.46M
                }
1334
1.38M
                t->bx -= x;
1335
1.38M
            }
1336
1.10M
            t->by -= y;
1337
1338
1.10M
            if (!has_chroma) continue;
1339
1340
819k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
819k
            if (b->uv_mode == CFL_PRED) {
1343
150k
                assert(!init_x && !init_y);
1344
1345
150k
                int16_t *const ac = t->scratch.ac;
1346
150k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
150k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
150k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
150k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
150k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
150k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
150k
                const int furthest_r =
1354
150k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
150k
                const int furthest_b =
1356
150k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
150k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
150k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
150k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
150k
                                                         cbw4 * 4, cbh4 * 4);
1361
451k
                for (int pl = 0; pl < 2; pl++) {
1362
301k
                    if (!b->cfl_alpha[pl]) continue;
1363
239k
                    int angle = 0;
1364
239k
                    const pixel *top_sb_edge = NULL;
1365
239k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
66.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
66.5k
                        const int sby = t->by >> f->sb_shift;
1368
66.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
66.5k
                    }
1370
239k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
239k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
239k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
239k
                    const enum IntraPredMode m =
1374
239k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
239k
                                                          ypos, ypos > ystart,
1376
239k
                                                          ts->tiling.col_end >> ss_hor,
1377
239k
                                                          ts->tiling.row_end >> ss_ver,
1378
239k
                                                          0, uv_dst[pl], stride,
1379
239k
                                                          top_sb_edge, DC_PRED, &angle,
1380
239k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
239k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
239k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
239k
                                           uv_t_dim->w * 4,
1384
239k
                                           uv_t_dim->h * 4,
1385
239k
                                           ac, b->cfl_alpha[pl]
1386
239k
                                           HIGHBD_CALL_SUFFIX);
1387
239k
                }
1388
150k
                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
669k
            } else if (b->pal_sz[1]) {
1394
1.63k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.63k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.63k
                const pixel (*pal)[8];
1397
1.63k
                const uint8_t *pal_idx;
1398
1.63k
                if (t->frame_thread.pass) {
1399
1.63k
                    const int p = t->frame_thread.pass & 1;
1400
1.63k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.63k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.63k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.63k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.63k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.63k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.63k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.63k
                                       f->cur.stride[1], pal[1],
1412
1.63k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.63k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.63k
                                       f->cur.stride[1], pal[2],
1415
1.63k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.63k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.63k
            }
1425
1426
819k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
819k
                                 sm_uv_flag(&t->l, cby4);
1428
819k
            const int uv_sb_has_tr =
1429
819k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
791k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
819k
            const int uv_sb_has_bl =
1432
819k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
791k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
819k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
2.45M
            for (int pl = 0; pl < 2; pl++) {
1436
3.41M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.77M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.77M
                {
1439
1.77M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.77M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.77M
                                        ((t->bx + init_x) >> ss_hor));
1442
3.94M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
2.16M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
2.16M
                    {
1445
2.16M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.92M
                            b->pal_sz[1])
1447
243k
                        {
1448
243k
                            goto skip_uv_pred;
1449
243k
                        }
1450
1451
1.91M
                        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.91M
                        const enum EdgeFlags edge_flags =
1456
1.91M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
853k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
1.35M
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.91M
                            ((x > (init_x >> ss_hor) ||
1460
1.53M
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
1.17M
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.91M
                        const pixel *top_sb_edge = NULL;
1463
1.91M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
547k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
547k
                            const int sby = t->by >> f->sb_shift;
1466
547k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
547k
                        }
1468
1.91M
                        const enum IntraPredMode uv_mode =
1469
1.91M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.91M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.91M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.91M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.91M
                        const enum IntraPredMode m =
1474
1.91M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.91M
                                                              ypos, ypos > ystart,
1476
1.91M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.91M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.91M
                                                              edge_flags, dst, stride,
1479
1.91M
                                                              top_sb_edge, uv_mode,
1480
1.91M
                                                              &angle, uv_t_dim->w,
1481
1.91M
                                                              uv_t_dim->h,
1482
1.91M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.91M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.91M
                        angle |= intra_edge_filter_flag;
1485
1.91M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.91M
                                                 uv_t_dim->w * 4,
1487
1.91M
                                                 uv_t_dim->h * 4,
1488
1.91M
                                                 angle | sm_uv_fl,
1489
1.91M
                                                 (4 * f->bw + ss_hor -
1490
1.91M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.91M
                                                 (4 * f->bh + ss_ver -
1492
1.91M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.91M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.91M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
2.16M
                    skip_uv_pred: {}
1505
2.16M
                        if (!b->skip) {
1506
776k
                            enum TxfmType txtp;
1507
776k
                            int eob;
1508
776k
                            coef *cf;
1509
776k
                            if (t->frame_thread.pass) {
1510
776k
                                const int p = t->frame_thread.pass & 1;
1511
776k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
776k
                                cf = ts->frame_thread[p].cf;
1513
776k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
776k
                                eob  = cbi >> 5;
1515
776k
                                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
776k
                            if (eob >= 0) {
1533
304k
                                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
304k
                                dsp->itx.itxfm_add[b->uvtx]
1537
304k
                                                  [txtp](dst, stride,
1538
304k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
304k
                                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
304k
                            }
1543
1.38M
                        } else if (!t->frame_thread.pass) {
1544
0
                            dav1d_memset_pow2[uv_t_dim->lw](&t->a->ccoef[pl][cbx4 + x], 0x40);
1545
0
                            dav1d_memset_pow2[uv_t_dim->lh](&t->l.ccoef[pl][cby4 + y], 0x40);
1546
0
                        }
1547
2.16M
                        dst += uv_t_dim->w * 4;
1548
2.16M
                    }
1549
1.77M
                    t->bx -= x << ss_hor;
1550
1.77M
                }
1551
1.63M
                t->by -= y << ss_ver;
1552
1.63M
            }
1553
819k
        }
1554
1.06M
    }
1555
1.04M
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
456k
{
1180
456k
    Dav1dTileState *const ts = t->ts;
1181
456k
    const Dav1dFrameContext *const f = t->f;
1182
456k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
456k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
456k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
456k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
456k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
456k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
456k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
456k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
456k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
456k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
358k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
332k
                           (bh4 > ss_ver || t->by & 1);
1194
456k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
456k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
456k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
456k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
456k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
919k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
462k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
462k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
936k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
473k
            if (b->pal_sz[0]) {
1208
1.88k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
1.88k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
1.88k
                const uint8_t *pal_idx;
1211
1.88k
                if (t->frame_thread.pass) {
1212
1.88k
                    const int p = t->frame_thread.pass & 1;
1213
1.88k
                    assert(ts->frame_thread[p].pal_idx);
1214
1.88k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
1.88k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
1.88k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
1.88k
                const pixel *const pal = t->frame_thread.pass ?
1220
1.88k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
1.88k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
1.88k
                    bytefn(t->scratch.pal)[0];
1223
1.88k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
1.88k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
1.88k
                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.88k
            }
1229
1230
473k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
473k
                                     sm_flag(&t->l, by4) |
1232
473k
                                     intra_edge_filter_flag);
1233
473k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
462k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
473k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
462k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
473k
            int y, x;
1238
473k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.03M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
566k
                 y += t_dim->h, t->by += t_dim->h)
1241
566k
            {
1242
566k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
566k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
566k
                                    t->bx + init_x);
1245
1.37M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
809k
                     x += t_dim->w, t->bx += t_dim->w)
1247
809k
                {
1248
809k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
807k
                    int angle = b->y_angle;
1251
807k
                    const enum EdgeFlags edge_flags =
1252
807k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
584k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
807k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
521k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
807k
                    const pixel *top_sb_edge = NULL;
1257
807k
                    if (!(t->by & (f->sb_step - 1))) {
1258
225k
                        top_sb_edge = f->ipred_edge[0];
1259
225k
                        const int sby = t->by >> f->sb_shift;
1260
225k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
225k
                    }
1262
807k
                    const enum IntraPredMode m =
1263
807k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
807k
                                                          t->bx > ts->tiling.col_start,
1265
807k
                                                          t->by,
1266
807k
                                                          t->by > ts->tiling.row_start,
1267
807k
                                                          ts->tiling.col_end,
1268
807k
                                                          ts->tiling.row_end,
1269
807k
                                                          edge_flags, dst,
1270
807k
                                                          f->cur.stride[0], top_sb_edge,
1271
807k
                                                          b->y_mode, &angle,
1272
807k
                                                          t_dim->w, t_dim->h,
1273
807k
                                                          f->seq_hdr->intra_edge_filter,
1274
807k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
807k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
807k
                                             t_dim->w * 4, t_dim->h * 4,
1277
807k
                                             angle | intra_flags,
1278
807k
                                             4 * f->bw - 4 * t->bx,
1279
807k
                                             4 * f->bh - 4 * t->by
1280
807k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
807k
                    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
809k
                skip_y_pred: {}
1293
809k
                    if (!b->skip) {
1294
257k
                        coef *cf;
1295
257k
                        int eob;
1296
257k
                        enum TxfmType txtp;
1297
257k
                        if (t->frame_thread.pass) {
1298
257k
                            const int p = t->frame_thread.pass & 1;
1299
257k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
257k
                            cf = ts->frame_thread[p].cf;
1301
257k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
257k
                            eob  = cbi >> 5;
1303
257k
                            txtp = cbi & 0x1f;
1304
257k
                        } 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
257k
                        if (eob >= 0) {
1317
176k
                            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
176k
                            dsp->itx.itxfm_add[b->tx]
1321
176k
                                              [txtp](dst,
1322
176k
                                                     f->cur.stride[0],
1323
176k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
176k
                            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
176k
                        }
1328
552k
                    } 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
809k
                    dst += 4 * t_dim->w;
1333
809k
                }
1334
566k
                t->bx -= x;
1335
566k
            }
1336
473k
            t->by -= y;
1337
1338
473k
            if (!has_chroma) continue;
1339
1340
322k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
322k
            if (b->uv_mode == CFL_PRED) {
1343
57.2k
                assert(!init_x && !init_y);
1344
1345
57.2k
                int16_t *const ac = t->scratch.ac;
1346
57.2k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
57.2k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
57.2k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
57.2k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
57.2k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
57.2k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
57.2k
                const int furthest_r =
1354
57.2k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
57.2k
                const int furthest_b =
1356
57.2k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
57.2k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
57.2k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
57.2k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
57.2k
                                                         cbw4 * 4, cbh4 * 4);
1361
171k
                for (int pl = 0; pl < 2; pl++) {
1362
114k
                    if (!b->cfl_alpha[pl]) continue;
1363
90.2k
                    int angle = 0;
1364
90.2k
                    const pixel *top_sb_edge = NULL;
1365
90.2k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
27.0k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
27.0k
                        const int sby = t->by >> f->sb_shift;
1368
27.0k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
27.0k
                    }
1370
90.2k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
90.2k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
90.2k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
90.2k
                    const enum IntraPredMode m =
1374
90.2k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
90.2k
                                                          ypos, ypos > ystart,
1376
90.2k
                                                          ts->tiling.col_end >> ss_hor,
1377
90.2k
                                                          ts->tiling.row_end >> ss_ver,
1378
90.2k
                                                          0, uv_dst[pl], stride,
1379
90.2k
                                                          top_sb_edge, DC_PRED, &angle,
1380
90.2k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
90.2k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
90.2k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
90.2k
                                           uv_t_dim->w * 4,
1384
90.2k
                                           uv_t_dim->h * 4,
1385
90.2k
                                           ac, b->cfl_alpha[pl]
1386
90.2k
                                           HIGHBD_CALL_SUFFIX);
1387
90.2k
                }
1388
57.2k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
264k
            } else if (b->pal_sz[1]) {
1394
537
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
537
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
537
                const pixel (*pal)[8];
1397
537
                const uint8_t *pal_idx;
1398
537
                if (t->frame_thread.pass) {
1399
537
                    const int p = t->frame_thread.pass & 1;
1400
537
                    assert(ts->frame_thread[p].pal_idx);
1401
537
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
537
                                              ((t->bx >> 1) + (t->by & 1))];
1403
537
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
537
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
537
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
537
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
537
                                       f->cur.stride[1], pal[1],
1412
537
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
537
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
537
                                       f->cur.stride[1], pal[2],
1415
537
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
537
                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
537
            }
1425
1426
322k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
322k
                                 sm_uv_flag(&t->l, cby4);
1428
322k
            const int uv_sb_has_tr =
1429
322k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
312k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
322k
            const int uv_sb_has_bl =
1432
322k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
312k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
322k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
966k
            for (int pl = 0; pl < 2; pl++) {
1436
1.32M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
680k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
680k
                {
1439
680k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
680k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
680k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.44M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
768k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
768k
                    {
1445
768k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
678k
                            b->pal_sz[1])
1447
91.6k
                        {
1448
91.6k
                            goto skip_uv_pred;
1449
91.6k
                        }
1450
1451
676k
                        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
676k
                        const enum EdgeFlags edge_flags =
1456
676k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
249k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
490k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
676k
                            ((x > (init_x >> ss_hor) ||
1460
589k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
397k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
676k
                        const pixel *top_sb_edge = NULL;
1463
676k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
234k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
234k
                            const int sby = t->by >> f->sb_shift;
1466
234k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
234k
                        }
1468
676k
                        const enum IntraPredMode uv_mode =
1469
676k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
676k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
676k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
676k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
676k
                        const enum IntraPredMode m =
1474
676k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
676k
                                                              ypos, ypos > ystart,
1476
676k
                                                              ts->tiling.col_end >> ss_hor,
1477
676k
                                                              ts->tiling.row_end >> ss_ver,
1478
676k
                                                              edge_flags, dst, stride,
1479
676k
                                                              top_sb_edge, uv_mode,
1480
676k
                                                              &angle, uv_t_dim->w,
1481
676k
                                                              uv_t_dim->h,
1482
676k
                                                              f->seq_hdr->intra_edge_filter,
1483
676k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
676k
                        angle |= intra_edge_filter_flag;
1485
676k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
676k
                                                 uv_t_dim->w * 4,
1487
676k
                                                 uv_t_dim->h * 4,
1488
676k
                                                 angle | sm_uv_fl,
1489
676k
                                                 (4 * f->bw + ss_hor -
1490
676k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
676k
                                                 (4 * f->bh + ss_ver -
1492
676k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
676k
                                                 HIGHBD_CALL_SUFFIX);
1494
676k
                        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
768k
                    skip_uv_pred: {}
1505
768k
                        if (!b->skip) {
1506
236k
                            enum TxfmType txtp;
1507
236k
                            int eob;
1508
236k
                            coef *cf;
1509
236k
                            if (t->frame_thread.pass) {
1510
236k
                                const int p = t->frame_thread.pass & 1;
1511
236k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
236k
                                cf = ts->frame_thread[p].cf;
1513
236k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
236k
                                eob  = cbi >> 5;
1515
236k
                                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
236k
                            if (eob >= 0) {
1533
79.5k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
79.5k
                                dsp->itx.itxfm_add[b->uvtx]
1537
79.5k
                                                  [txtp](dst, stride,
1538
79.5k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
79.5k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
79.5k
                            }
1543
532k
                        } 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
768k
                        dst += uv_t_dim->w * 4;
1548
768k
                    }
1549
680k
                    t->bx -= x << ss_hor;
1550
680k
                }
1551
644k
                t->by -= y << ss_ver;
1552
644k
            }
1553
322k
        }
1554
462k
    }
1555
456k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
589k
{
1180
589k
    Dav1dTileState *const ts = t->ts;
1181
589k
    const Dav1dFrameContext *const f = t->f;
1182
589k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
589k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
589k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
589k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
589k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
589k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
589k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
589k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
589k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
589k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
537k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
503k
                           (bh4 > ss_ver || t->by & 1);
1194
589k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
589k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
589k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
589k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
589k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.19M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
605k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
605k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.23M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
627k
            if (b->pal_sz[0]) {
1208
6.20k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
6.20k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
6.20k
                const uint8_t *pal_idx;
1211
6.20k
                if (t->frame_thread.pass) {
1212
6.20k
                    const int p = t->frame_thread.pass & 1;
1213
6.20k
                    assert(ts->frame_thread[p].pal_idx);
1214
6.20k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
6.20k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
6.20k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
6.20k
                const pixel *const pal = t->frame_thread.pass ?
1220
6.20k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
6.20k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
6.20k
                    bytefn(t->scratch.pal)[0];
1223
6.20k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
6.20k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
6.20k
                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
6.20k
            }
1229
1230
627k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
627k
                                     sm_flag(&t->l, by4) |
1232
627k
                                     intra_edge_filter_flag);
1233
627k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
605k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
627k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
605k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
627k
            int y, x;
1238
627k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.44M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
819k
                 y += t_dim->h, t->by += t_dim->h)
1241
818k
            {
1242
818k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
818k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
818k
                                    t->bx + init_x);
1245
2.47M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.65M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.65M
                {
1248
1.65M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.64M
                    int angle = b->y_angle;
1251
1.64M
                    const enum EdgeFlags edge_flags =
1252
1.64M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
1.24M
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.64M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
1.17M
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.64M
                    const pixel *top_sb_edge = NULL;
1257
1.64M
                    if (!(t->by & (f->sb_step - 1))) {
1258
250k
                        top_sb_edge = f->ipred_edge[0];
1259
250k
                        const int sby = t->by >> f->sb_shift;
1260
250k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
250k
                    }
1262
1.64M
                    const enum IntraPredMode m =
1263
1.64M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.64M
                                                          t->bx > ts->tiling.col_start,
1265
1.64M
                                                          t->by,
1266
1.64M
                                                          t->by > ts->tiling.row_start,
1267
1.64M
                                                          ts->tiling.col_end,
1268
1.64M
                                                          ts->tiling.row_end,
1269
1.64M
                                                          edge_flags, dst,
1270
1.64M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.64M
                                                          b->y_mode, &angle,
1272
1.64M
                                                          t_dim->w, t_dim->h,
1273
1.64M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.64M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.64M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.64M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.64M
                                             angle | intra_flags,
1278
1.64M
                                             4 * f->bw - 4 * t->bx,
1279
1.64M
                                             4 * f->bh - 4 * t->by
1280
1.64M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.64M
                    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.65M
                skip_y_pred: {}
1293
1.65M
                    if (!b->skip) {
1294
623k
                        coef *cf;
1295
623k
                        int eob;
1296
623k
                        enum TxfmType txtp;
1297
623k
                        if (t->frame_thread.pass) {
1298
623k
                            const int p = t->frame_thread.pass & 1;
1299
623k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
623k
                            cf = ts->frame_thread[p].cf;
1301
623k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
623k
                            eob  = cbi >> 5;
1303
623k
                            txtp = cbi & 0x1f;
1304
623k
                        } 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
623k
                        if (eob >= 0) {
1317
480k
                            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
480k
                            dsp->itx.itxfm_add[b->tx]
1321
480k
                                              [txtp](dst,
1322
480k
                                                     f->cur.stride[0],
1323
480k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
480k
                            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
480k
                        }
1328
1.03M
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.65M
                    dst += 4 * t_dim->w;
1333
1.65M
                }
1334
819k
                t->bx -= x;
1335
819k
            }
1336
627k
            t->by -= y;
1337
1338
627k
            if (!has_chroma) continue;
1339
1340
497k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
497k
            if (b->uv_mode == CFL_PRED) {
1343
93.2k
                assert(!init_x && !init_y);
1344
1345
93.2k
                int16_t *const ac = t->scratch.ac;
1346
93.2k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
93.2k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
93.2k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
93.2k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
93.2k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
93.2k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
93.2k
                const int furthest_r =
1354
93.2k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
93.2k
                const int furthest_b =
1356
93.2k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
93.2k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
93.2k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
93.2k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
93.2k
                                                         cbw4 * 4, cbh4 * 4);
1361
279k
                for (int pl = 0; pl < 2; pl++) {
1362
186k
                    if (!b->cfl_alpha[pl]) continue;
1363
149k
                    int angle = 0;
1364
149k
                    const pixel *top_sb_edge = NULL;
1365
149k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
39.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
39.5k
                        const int sby = t->by >> f->sb_shift;
1368
39.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
39.5k
                    }
1370
149k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
149k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
149k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
149k
                    const enum IntraPredMode m =
1374
149k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
149k
                                                          ypos, ypos > ystart,
1376
149k
                                                          ts->tiling.col_end >> ss_hor,
1377
149k
                                                          ts->tiling.row_end >> ss_ver,
1378
149k
                                                          0, uv_dst[pl], stride,
1379
149k
                                                          top_sb_edge, DC_PRED, &angle,
1380
149k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
149k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
149k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
149k
                                           uv_t_dim->w * 4,
1384
149k
                                           uv_t_dim->h * 4,
1385
149k
                                           ac, b->cfl_alpha[pl]
1386
149k
                                           HIGHBD_CALL_SUFFIX);
1387
149k
                }
1388
93.2k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
404k
            } else if (b->pal_sz[1]) {
1394
1.09k
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
1.09k
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
1.09k
                const pixel (*pal)[8];
1397
1.09k
                const uint8_t *pal_idx;
1398
1.09k
                if (t->frame_thread.pass) {
1399
1.09k
                    const int p = t->frame_thread.pass & 1;
1400
1.09k
                    assert(ts->frame_thread[p].pal_idx);
1401
1.09k
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
1.09k
                                              ((t->bx >> 1) + (t->by & 1))];
1403
1.09k
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
1.09k
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
1.09k
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
1.09k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
1.09k
                                       f->cur.stride[1], pal[1],
1412
1.09k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
1.09k
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
1.09k
                                       f->cur.stride[1], pal[2],
1415
1.09k
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
1.09k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1417
0
                    hex_dump(((pixel *) f->cur.data[1]) + uv_dstoff,
1418
0
                             PXSTRIDE(f->cur.stride[1]),
1419
0
                             cbw4 * 4, cbh4 * 4, "u-pal-pred");
1420
0
                    hex_dump(((pixel *) f->cur.data[2]) + uv_dstoff,
1421
0
                             PXSTRIDE(f->cur.stride[1]),
1422
0
                             cbw4 * 4, cbh4 * 4, "v-pal-pred");
1423
0
                }
1424
1.09k
            }
1425
1426
497k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
497k
                                 sm_uv_flag(&t->l, cby4);
1428
497k
            const int uv_sb_has_tr =
1429
497k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
478k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
497k
            const int uv_sb_has_bl =
1432
497k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
478k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
497k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.49M
            for (int pl = 0; pl < 2; pl++) {
1436
2.09M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.09M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.09M
                {
1439
1.09M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.09M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.09M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.49M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.39M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.39M
                    {
1445
1.39M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.24M
                            b->pal_sz[1])
1447
151k
                        {
1448
151k
                            goto skip_uv_pred;
1449
151k
                        }
1450
1451
1.24M
                        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.24M
                        const enum EdgeFlags edge_flags =
1456
1.24M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
603k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
869k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.24M
                            ((x > (init_x >> ss_hor) ||
1460
945k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
773k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.24M
                        const pixel *top_sb_edge = NULL;
1463
1.24M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
312k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
312k
                            const int sby = t->by >> f->sb_shift;
1466
312k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
312k
                        }
1468
1.24M
                        const enum IntraPredMode uv_mode =
1469
1.24M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.24M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.24M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.24M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.24M
                        const enum IntraPredMode m =
1474
1.24M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.24M
                                                              ypos, ypos > ystart,
1476
1.24M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.24M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.24M
                                                              edge_flags, dst, stride,
1479
1.24M
                                                              top_sb_edge, uv_mode,
1480
1.24M
                                                              &angle, uv_t_dim->w,
1481
1.24M
                                                              uv_t_dim->h,
1482
1.24M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.24M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.24M
                        angle |= intra_edge_filter_flag;
1485
1.24M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.24M
                                                 uv_t_dim->w * 4,
1487
1.24M
                                                 uv_t_dim->h * 4,
1488
1.24M
                                                 angle | sm_uv_fl,
1489
1.24M
                                                 (4 * f->bw + ss_hor -
1490
1.24M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.24M
                                                 (4 * f->bh + ss_ver -
1492
1.24M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.24M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.24M
                        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.39M
                    skip_uv_pred: {}
1505
1.39M
                        if (!b->skip) {
1506
540k
                            enum TxfmType txtp;
1507
540k
                            int eob;
1508
540k
                            coef *cf;
1509
540k
                            if (t->frame_thread.pass) {
1510
540k
                                const int p = t->frame_thread.pass & 1;
1511
540k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
540k
                                cf = ts->frame_thread[p].cf;
1513
540k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
540k
                                eob  = cbi >> 5;
1515
540k
                                txtp = cbi & 0x1f;
1516
540k
                            } 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
540k
                            if (eob >= 0) {
1533
224k
                                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
224k
                                dsp->itx.itxfm_add[b->uvtx]
1537
224k
                                                  [txtp](dst, stride,
1538
224k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
224k
                                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
224k
                            }
1543
854k
                        } 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.39M
                        dst += uv_t_dim->w * 4;
1548
1.39M
                    }
1549
1.09M
                    t->bx -= x << ss_hor;
1550
1.09M
                }
1551
994k
                t->by -= y << ss_ver;
1552
994k
            }
1553
497k
        }
1554
605k
    }
1555
589k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
409k
{
1560
409k
    Dav1dTileState *const ts = t->ts;
1561
409k
    const Dav1dFrameContext *const f = t->f;
1562
409k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
409k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
409k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
409k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
409k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
409k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
409k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
409k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
409k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
345k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
334k
                           (bh4 > ss_ver || t->by & 1);
1573
409k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
409k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
409k
    int res;
1576
1577
    // prediction
1578
409k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
409k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
409k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
409k
    const ptrdiff_t uvdstoff =
1582
409k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
409k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
24.2k
        assert(!f->frame_hdr->super_res.enabled);
1586
24.2k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
24.2k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
24.2k
        if (res) return res;
1589
36.2k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
24.1k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
24.1k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
24.1k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
24.1k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
24.1k
            if (res) return res;
1595
24.1k
        }
1596
385k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
329k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
329k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
329k
        if (imin(bw4, bh4) > 1 &&
1601
203k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
202k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
3.33k
        {
1604
3.33k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
3.33k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
3.33k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
3.33k
            if (res) return res;
1608
326k
        } else {
1609
326k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
326k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
326k
            if (res) return res;
1612
326k
            if (b->motion_mode == MM_OBMC) {
1613
61.9k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
61.9k
                if (res) return res;
1615
61.9k
            }
1616
326k
        }
1617
329k
        if (b->interintra_type) {
1618
16.5k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
16.5k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
14.0k
                                   SMOOTH_PRED : b->interintra_mode;
1621
16.5k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
16.5k
            int angle = 0;
1623
16.5k
            const pixel *top_sb_edge = NULL;
1624
16.5k
            if (!(t->by & (f->sb_step - 1))) {
1625
3.49k
                top_sb_edge = f->ipred_edge[0];
1626
3.49k
                const int sby = t->by >> f->sb_shift;
1627
3.49k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
3.49k
            }
1629
16.5k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
16.5k
                                                  t->by, t->by > ts->tiling.row_start,
1631
16.5k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
16.5k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
16.5k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
16.5k
                                                  HIGHBD_CALL_SUFFIX);
1635
16.5k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
16.5k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
16.5k
                                     HIGHBD_CALL_SUFFIX);
1638
16.5k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
16.5k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
16.5k
        }
1641
1642
329k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
264k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
264k
        refmvs_block *const *r;
1647
264k
        if (is_sub8x8) {
1648
9.57k
            assert(ss_hor == 1);
1649
9.57k
            r = &t->rt.r[(t->by & 31) + 5];
1650
9.57k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
9.57k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
9.57k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.87k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
9.57k
        }
1655
1656
        // chroma prediction
1657
264k
        if (is_sub8x8) {
1658
8.70k
            assert(ss_hor == 1);
1659
8.70k
            ptrdiff_t h_off = 0, v_off = 0;
1660
8.70k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
7.02k
                for (int pl = 0; pl < 2; pl++) {
1662
4.68k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
4.68k
                             NULL, f->cur.stride[1],
1664
4.68k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
4.68k
                             r[-1][t->bx - 1].mv.mv[0],
1666
4.68k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
4.68k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
4.68k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
4.68k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
4.68k
                    if (res) return res;
1671
4.68k
                }
1672
2.34k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
2.34k
                h_off = 2;
1674
2.34k
            }
1675
8.70k
            if (bw4 == 1) {
1676
6.24k
                const enum Filter2d left_filter_2d =
1677
6.24k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
18.7k
                for (int pl = 0; pl < 2; pl++) {
1679
12.4k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
12.4k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
12.4k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
12.4k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
12.4k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
12.4k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
12.4k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
12.4k
                    if (res) return res;
1687
12.4k
                }
1688
6.24k
                h_off = 2;
1689
6.24k
            }
1690
8.70k
            if (bh4 == ss_ver) {
1691
4.79k
                const enum Filter2d top_filter_2d =
1692
4.79k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
14.3k
                for (int pl = 0; pl < 2; pl++) {
1694
9.58k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
9.58k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
9.58k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
9.58k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
9.58k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
9.58k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
9.58k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
9.58k
                    if (res) return res;
1702
9.58k
                }
1703
4.79k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
4.79k
            }
1705
26.1k
            for (int pl = 0; pl < 2; pl++) {
1706
17.4k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
17.4k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
17.4k
                         refp, b->ref[0], filter_2d);
1709
17.4k
                if (res) return res;
1710
17.4k
            }
1711
256k
        } else {
1712
256k
            if (imin(cbw4, cbh4) > 1 &&
1713
151k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
150k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
2.99k
            {
1716
8.97k
                for (int pl = 0; pl < 2; pl++) {
1717
5.98k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
5.98k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
5.98k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
5.98k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
5.98k
                    if (res) return res;
1722
5.98k
                }
1723
253k
            } else {
1724
759k
                for (int pl = 0; pl < 2; pl++) {
1725
506k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
506k
                             NULL, f->cur.stride[1],
1727
506k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
506k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
506k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
506k
                    if (res) return res;
1731
506k
                    if (b->motion_mode == MM_OBMC) {
1732
115k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
115k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
115k
                        if (res) return res;
1735
115k
                    }
1736
506k
                }
1737
253k
            }
1738
256k
            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
16.1k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
48.5k
                for (int pl = 0; pl < 2; pl++) {
1745
32.3k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
32.3k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
32.3k
                    enum IntraPredMode m =
1748
32.3k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
27.3k
                        SMOOTH_PRED : b->interintra_mode;
1750
32.3k
                    int angle = 0;
1751
32.3k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
32.3k
                    const pixel *top_sb_edge = NULL;
1753
32.3k
                    if (!(t->by & (f->sb_step - 1))) {
1754
6.33k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
6.33k
                        const int sby = t->by >> f->sb_shift;
1756
6.33k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
6.33k
                    }
1758
32.3k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
32.3k
                                                          (t->bx >> ss_hor) >
1760
32.3k
                                                              (ts->tiling.col_start >> ss_hor),
1761
32.3k
                                                          t->by >> ss_ver,
1762
32.3k
                                                          (t->by >> ss_ver) >
1763
32.3k
                                                              (ts->tiling.row_start >> ss_ver),
1764
32.3k
                                                          ts->tiling.col_end >> ss_hor,
1765
32.3k
                                                          ts->tiling.row_end >> ss_ver,
1766
32.3k
                                                          0, uvdst, f->cur.stride[1],
1767
32.3k
                                                          top_sb_edge, m,
1768
32.3k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
32.3k
                                                          HIGHBD_CALL_SUFFIX);
1770
32.3k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
32.3k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
32.3k
                                             HIGHBD_CALL_SUFFIX);
1773
32.3k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
32.3k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
32.3k
                }
1776
16.1k
            }
1777
256k
        }
1778
1779
329k
    skip_inter_chroma_pred: {}
1780
329k
        t->tl_4x4_filter = filter_2d;
1781
329k
    } else {
1782
55.9k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
55.9k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
55.9k
        int jnt_weight;
1786
55.9k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
55.9k
        const uint8_t *mask;
1788
1789
167k
        for (int i = 0; i < 2; i++) {
1790
111k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
111k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
3.51k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
3.51k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
3.51k
                if (res) return res;
1796
108k
            } else {
1797
108k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
108k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
108k
                if (res) return res;
1800
108k
            }
1801
111k
        }
1802
55.9k
        switch (b->comp_type) {
1803
46.2k
        case COMP_INTER_AVG:
1804
46.2k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
46.2k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
46.2k
            break;
1807
2.67k
        case COMP_INTER_WEIGHTED_AVG:
1808
2.67k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
2.67k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
2.67k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
2.67k
            break;
1812
4.73k
        case COMP_INTER_SEG:
1813
4.73k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
4.73k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
4.73k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
4.73k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
4.73k
            mask = seg_mask;
1818
4.73k
            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.79k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
2.33k
            break;
1827
55.9k
        }
1828
1829
        // chroma
1830
154k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
308k
            for (int i = 0; i < 2; i++) {
1832
205k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
205k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
27.2k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
3.64k
                {
1836
3.64k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
3.64k
                                      b_dim, 1 + pl,
1838
3.64k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
3.64k
                    if (res) return res;
1840
201k
                } else {
1841
201k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
201k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
201k
                    if (res) return res;
1844
201k
                }
1845
205k
            }
1846
102k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
102k
            switch (b->comp_type) {
1848
86.8k
            case COMP_INTER_AVG:
1849
86.8k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
86.8k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
86.8k
                            HIGHBD_CALL_SUFFIX);
1852
86.8k
                break;
1853
3.78k
            case COMP_INTER_WEIGHTED_AVG:
1854
3.78k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
3.78k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
3.78k
                              HIGHBD_CALL_SUFFIX);
1857
3.78k
                break;
1858
3.59k
            case COMP_INTER_WEDGE:
1859
12.0k
            case COMP_INTER_SEG:
1860
12.0k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
12.0k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
12.0k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
12.0k
                             HIGHBD_CALL_SUFFIX);
1864
12.0k
                break;
1865
102k
            }
1866
102k
        }
1867
55.9k
    }
1868
1869
409k
    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
409k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
409k
    if (b->skip) {
1882
        // reset coef contexts
1883
192k
        BlockContext *const a = t->a;
1884
192k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
192k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
192k
        if (has_chroma) {
1887
142k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
142k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
142k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
142k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
142k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
142k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
142k
        }
1894
192k
        return 0;
1895
192k
    }
1896
1897
217k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
217k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
217k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
442k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
455k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
229k
            int y_off = !!init_y, y;
1905
229k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
470k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
241k
                 y += ytx->h, y_off++)
1908
241k
            {
1909
241k
                int x, x_off = !!init_x;
1910
536k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
295k
                     x += ytx->w, x_off++)
1912
295k
                {
1913
295k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
295k
                                   x_off, y_off, &dst[x * 4]);
1915
295k
                    t->bx += ytx->w;
1916
295k
                }
1917
241k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
241k
                t->bx -= x;
1919
241k
                t->by += ytx->h;
1920
241k
            }
1921
229k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
229k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
591k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
394k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
394k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
394k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
837k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
443k
                {
1931
443k
                    int x;
1932
443k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
1.02M
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
582k
                    {
1935
582k
                        coef *cf;
1936
582k
                        int eob;
1937
582k
                        enum TxfmType txtp;
1938
582k
                        if (t->frame_thread.pass) {
1939
582k
                            const int p = t->frame_thread.pass & 1;
1940
582k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
582k
                            cf = ts->frame_thread[p].cf;
1942
582k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
582k
                            eob  = cbi >> 5;
1944
582k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            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
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
582k
                        if (eob >= 0) {
1964
178k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
178k
                            dsp->itx.itxfm_add[b->uvtx]
1967
178k
                                              [txtp](&uvdst[4 * x],
1968
178k
                                                     f->cur.stride[1],
1969
178k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
178k
                            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
178k
                        }
1974
582k
                        t->bx += uvtx->w << ss_hor;
1975
582k
                    }
1976
443k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
443k
                    t->bx -= x << ss_hor;
1978
443k
                    t->by += uvtx->h << ss_ver;
1979
443k
                }
1980
394k
                t->by -= y << ss_ver;
1981
394k
            }
1982
229k
        }
1983
225k
    }
1984
217k
    return 0;
1985
409k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
211k
{
1560
211k
    Dav1dTileState *const ts = t->ts;
1561
211k
    const Dav1dFrameContext *const f = t->f;
1562
211k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
211k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
211k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
211k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
211k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
211k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
211k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
211k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
211k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
184k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
176k
                           (bh4 > ss_ver || t->by & 1);
1573
211k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
211k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
211k
    int res;
1576
1577
    // prediction
1578
211k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
211k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
211k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
211k
    const ptrdiff_t uvdstoff =
1582
211k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
211k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
16.7k
        assert(!f->frame_hdr->super_res.enabled);
1586
16.7k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
16.7k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
16.7k
        if (res) return res;
1589
17.8k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
11.9k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
11.9k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
11.9k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
11.9k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
11.9k
            if (res) return res;
1595
11.9k
        }
1596
195k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
161k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
161k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
161k
        if (imin(bw4, bh4) > 1 &&
1601
97.2k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
96.3k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.43k
        {
1604
1.43k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.43k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.43k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.43k
            if (res) return res;
1608
160k
        } else {
1609
160k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
160k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
160k
            if (res) return res;
1612
160k
            if (b->motion_mode == MM_OBMC) {
1613
28.0k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
28.0k
                if (res) return res;
1615
28.0k
            }
1616
160k
        }
1617
161k
        if (b->interintra_type) {
1618
6.85k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
6.85k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
5.72k
                                   SMOOTH_PRED : b->interintra_mode;
1621
6.85k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
6.85k
            int angle = 0;
1623
6.85k
            const pixel *top_sb_edge = NULL;
1624
6.85k
            if (!(t->by & (f->sb_step - 1))) {
1625
1.30k
                top_sb_edge = f->ipred_edge[0];
1626
1.30k
                const int sby = t->by >> f->sb_shift;
1627
1.30k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
1.30k
            }
1629
6.85k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
6.85k
                                                  t->by, t->by > ts->tiling.row_start,
1631
6.85k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
6.85k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
6.85k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
6.85k
                                                  HIGHBD_CALL_SUFFIX);
1635
6.85k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
6.85k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
6.85k
                                     HIGHBD_CALL_SUFFIX);
1638
6.85k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
6.85k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
6.85k
        }
1641
1642
161k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
134k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
134k
        refmvs_block *const *r;
1647
134k
        if (is_sub8x8) {
1648
7.29k
            assert(ss_hor == 1);
1649
7.29k
            r = &t->rt.r[(t->by & 31) + 5];
1650
7.29k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
7.29k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
7.29k
            if (bw4 == 1 && bh4 == ss_ver)
1653
2.12k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
7.29k
        }
1655
1656
        // chroma prediction
1657
134k
        if (is_sub8x8) {
1658
6.46k
            assert(ss_hor == 1);
1659
6.46k
            ptrdiff_t h_off = 0, v_off = 0;
1660
6.46k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
4.81k
                for (int pl = 0; pl < 2; pl++) {
1662
3.21k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
3.21k
                             NULL, f->cur.stride[1],
1664
3.21k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
3.21k
                             r[-1][t->bx - 1].mv.mv[0],
1666
3.21k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
3.21k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
3.21k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
3.21k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
3.21k
                    if (res) return res;
1671
3.21k
                }
1672
1.60k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
1.60k
                h_off = 2;
1674
1.60k
            }
1675
6.46k
            if (bw4 == 1) {
1676
4.70k
                const enum Filter2d left_filter_2d =
1677
4.70k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
14.1k
                for (int pl = 0; pl < 2; pl++) {
1679
9.41k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
9.41k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
9.41k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
9.41k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
9.41k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
9.41k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
9.41k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
9.41k
                    if (res) return res;
1687
9.41k
                }
1688
4.70k
                h_off = 2;
1689
4.70k
            }
1690
6.46k
            if (bh4 == ss_ver) {
1691
3.36k
                const enum Filter2d top_filter_2d =
1692
3.36k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
10.0k
                for (int pl = 0; pl < 2; pl++) {
1694
6.72k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
6.72k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
6.72k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
6.72k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
6.72k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
6.72k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
6.72k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
6.72k
                    if (res) return res;
1702
6.72k
                }
1703
3.36k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
3.36k
            }
1705
19.3k
            for (int pl = 0; pl < 2; pl++) {
1706
12.9k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
12.9k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
12.9k
                         refp, b->ref[0], filter_2d);
1709
12.9k
                if (res) return res;
1710
12.9k
            }
1711
127k
        } else {
1712
127k
            if (imin(cbw4, cbh4) > 1 &&
1713
71.7k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
70.8k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.38k
            {
1716
4.14k
                for (int pl = 0; pl < 2; pl++) {
1717
2.76k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
2.76k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
2.76k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
2.76k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
2.76k
                    if (res) return res;
1722
2.76k
                }
1723
126k
            } else {
1724
379k
                for (int pl = 0; pl < 2; pl++) {
1725
252k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
252k
                             NULL, f->cur.stride[1],
1727
252k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
252k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
252k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
252k
                    if (res) return res;
1731
252k
                    if (b->motion_mode == MM_OBMC) {
1732
54.7k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
54.7k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
54.7k
                        if (res) return res;
1735
54.7k
                    }
1736
252k
                }
1737
126k
            }
1738
127k
            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
6.83k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
20.4k
                for (int pl = 0; pl < 2; pl++) {
1745
13.6k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
13.6k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
13.6k
                    enum IntraPredMode m =
1748
13.6k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
11.4k
                        SMOOTH_PRED : b->interintra_mode;
1750
13.6k
                    int angle = 0;
1751
13.6k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
13.6k
                    const pixel *top_sb_edge = NULL;
1753
13.6k
                    if (!(t->by & (f->sb_step - 1))) {
1754
2.60k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
2.60k
                        const int sby = t->by >> f->sb_shift;
1756
2.60k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
2.60k
                    }
1758
13.6k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
13.6k
                                                          (t->bx >> ss_hor) >
1760
13.6k
                                                              (ts->tiling.col_start >> ss_hor),
1761
13.6k
                                                          t->by >> ss_ver,
1762
13.6k
                                                          (t->by >> ss_ver) >
1763
13.6k
                                                              (ts->tiling.row_start >> ss_ver),
1764
13.6k
                                                          ts->tiling.col_end >> ss_hor,
1765
13.6k
                                                          ts->tiling.row_end >> ss_ver,
1766
13.6k
                                                          0, uvdst, f->cur.stride[1],
1767
13.6k
                                                          top_sb_edge, m,
1768
13.6k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
13.6k
                                                          HIGHBD_CALL_SUFFIX);
1770
13.6k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
13.6k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
13.6k
                                             HIGHBD_CALL_SUFFIX);
1773
13.6k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
13.6k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
13.6k
                }
1776
6.83k
            }
1777
127k
        }
1778
1779
161k
    skip_inter_chroma_pred: {}
1780
161k
        t->tl_4x4_filter = filter_2d;
1781
161k
    } else {
1782
33.4k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
33.4k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
33.4k
        int jnt_weight;
1786
33.4k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
33.4k
        const uint8_t *mask;
1788
1789
100k
        for (int i = 0; i < 2; i++) {
1790
66.8k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
66.8k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
2.02k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
2.02k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
2.02k
                if (res) return res;
1796
64.8k
            } else {
1797
64.8k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
64.8k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
64.8k
                if (res) return res;
1800
64.8k
            }
1801
66.8k
        }
1802
33.4k
        switch (b->comp_type) {
1803
28.0k
        case COMP_INTER_AVG:
1804
28.0k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
28.0k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
28.0k
            break;
1807
1.06k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.06k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.06k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.06k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.06k
            break;
1812
2.70k
        case COMP_INTER_SEG:
1813
2.70k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
2.70k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
2.70k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
2.70k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
2.70k
            mask = seg_mask;
1818
2.70k
            break;
1819
1.63k
        case COMP_INTER_WEDGE:
1820
1.63k
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
1.63k
            dsp->mc.mask(dst, f->cur.stride[0],
1822
1.63k
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
1.63k
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
1.63k
            if (has_chroma)
1825
1.46k
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
1.63k
            break;
1827
33.4k
        }
1828
1829
        // chroma
1830
94.1k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
188k
            for (int i = 0; i < 2; i++) {
1832
125k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
125k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
15.6k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.73k
                {
1836
1.73k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.73k
                                      b_dim, 1 + pl,
1838
1.73k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.73k
                    if (res) return res;
1840
123k
                } else {
1841
123k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
123k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
123k
                    if (res) return res;
1844
123k
                }
1845
125k
            }
1846
62.7k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
62.7k
            switch (b->comp_type) {
1848
53.7k
            case COMP_INTER_AVG:
1849
53.7k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
53.7k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
53.7k
                            HIGHBD_CALL_SUFFIX);
1852
53.7k
                break;
1853
954
            case COMP_INTER_WEIGHTED_AVG:
1854
954
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
954
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
954
                              HIGHBD_CALL_SUFFIX);
1857
954
                break;
1858
2.92k
            case COMP_INTER_WEDGE:
1859
8.08k
            case COMP_INTER_SEG:
1860
8.08k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
8.08k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
8.08k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
8.08k
                             HIGHBD_CALL_SUFFIX);
1864
8.08k
                break;
1865
62.7k
            }
1866
62.7k
        }
1867
33.4k
    }
1868
1869
211k
    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1870
0
        hex_dump(dst, f->cur.stride[0], b_dim[0] * 4, b_dim[1] * 4, "y-pred");
1871
0
        if (has_chroma) {
1872
0
            hex_dump(&((pixel *) f->cur.data[1])[uvdstoff], f->cur.stride[1],
1873
0
                     cbw4 * 4, cbh4 * 4, "u-pred");
1874
0
            hex_dump(&((pixel *) f->cur.data[2])[uvdstoff], f->cur.stride[1],
1875
0
                     cbw4 * 4, cbh4 * 4, "v-pred");
1876
0
        }
1877
0
    }
1878
1879
211k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
211k
    if (b->skip) {
1882
        // reset coef contexts
1883
100k
        BlockContext *const a = t->a;
1884
100k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
100k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
100k
        if (has_chroma) {
1887
74.9k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
74.9k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
74.9k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
74.9k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
74.9k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
74.9k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
74.9k
        }
1894
100k
        return 0;
1895
100k
    }
1896
1897
111k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
111k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
111k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
227k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
234k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
118k
            int y_off = !!init_y, y;
1905
118k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
238k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
120k
                 y += ytx->h, y_off++)
1908
120k
            {
1909
120k
                int x, x_off = !!init_x;
1910
248k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
128k
                     x += ytx->w, x_off++)
1912
128k
                {
1913
128k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
128k
                                   x_off, y_off, &dst[x * 4]);
1915
128k
                    t->bx += ytx->w;
1916
128k
                }
1917
120k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
120k
                t->bx -= x;
1919
120k
                t->by += ytx->h;
1920
120k
            }
1921
118k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
118k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
308k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
205k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
205k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
205k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
429k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
223k
                {
1931
223k
                    int x;
1932
223k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
483k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
260k
                    {
1935
260k
                        coef *cf;
1936
260k
                        int eob;
1937
260k
                        enum TxfmType txtp;
1938
260k
                        if (t->frame_thread.pass) {
1939
260k
                            const int p = t->frame_thread.pass & 1;
1940
260k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
260k
                            cf = ts->frame_thread[p].cf;
1942
260k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
260k
                            eob  = cbi >> 5;
1944
260k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            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
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
260k
                        if (eob >= 0) {
1964
64.5k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
64.5k
                            dsp->itx.itxfm_add[b->uvtx]
1967
64.5k
                                              [txtp](&uvdst[4 * x],
1968
64.5k
                                                     f->cur.stride[1],
1969
64.5k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
64.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
64.5k
                        }
1974
260k
                        t->bx += uvtx->w << ss_hor;
1975
260k
                    }
1976
223k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
223k
                    t->bx -= x << ss_hor;
1978
223k
                    t->by += uvtx->h << ss_ver;
1979
223k
                }
1980
205k
                t->by -= y << ss_ver;
1981
205k
            }
1982
118k
        }
1983
115k
    }
1984
111k
    return 0;
1985
211k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
197k
{
1560
197k
    Dav1dTileState *const ts = t->ts;
1561
197k
    const Dav1dFrameContext *const f = t->f;
1562
197k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
197k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
197k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
197k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
197k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
197k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
197k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
197k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
197k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
161k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
158k
                           (bh4 > ss_ver || t->by & 1);
1573
197k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
197k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
197k
    int res;
1576
1577
    // prediction
1578
197k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
197k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
197k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
197k
    const ptrdiff_t uvdstoff =
1582
197k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
197k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
7.44k
        assert(!f->frame_hdr->super_res.enabled);
1586
7.44k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
7.44k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
7.44k
        if (res) return res;
1589
18.3k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
12.2k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
12.2k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
12.2k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
12.2k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
12.2k
            if (res) return res;
1595
12.2k
        }
1596
190k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
167k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
167k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
167k
        if (imin(bw4, bh4) > 1 &&
1601
106k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
105k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.90k
        {
1604
1.90k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.90k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.90k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.90k
            if (res) return res;
1608
166k
        } else {
1609
166k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
166k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
166k
            if (res) return res;
1612
166k
            if (b->motion_mode == MM_OBMC) {
1613
33.8k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
33.8k
                if (res) return res;
1615
33.8k
            }
1616
166k
        }
1617
167k
        if (b->interintra_type) {
1618
9.70k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
9.70k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
8.28k
                                   SMOOTH_PRED : b->interintra_mode;
1621
9.70k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
9.70k
            int angle = 0;
1623
9.70k
            const pixel *top_sb_edge = NULL;
1624
9.70k
            if (!(t->by & (f->sb_step - 1))) {
1625
2.18k
                top_sb_edge = f->ipred_edge[0];
1626
2.18k
                const int sby = t->by >> f->sb_shift;
1627
2.18k
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
2.18k
            }
1629
9.70k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
9.70k
                                                  t->by, t->by > ts->tiling.row_start,
1631
9.70k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
9.70k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
9.70k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
9.70k
                                                  HIGHBD_CALL_SUFFIX);
1635
9.70k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
9.70k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
9.70k
                                     HIGHBD_CALL_SUFFIX);
1638
9.70k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
9.70k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
9.70k
        }
1641
1642
167k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
130k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
130k
        refmvs_block *const *r;
1647
130k
        if (is_sub8x8) {
1648
2.27k
            assert(ss_hor == 1);
1649
2.27k
            r = &t->rt.r[(t->by & 31) + 5];
1650
2.27k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
2.27k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
2.27k
            if (bw4 == 1 && bh4 == ss_ver)
1653
751
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
2.27k
        }
1655
1656
        // chroma prediction
1657
130k
        if (is_sub8x8) {
1658
2.23k
            assert(ss_hor == 1);
1659
2.23k
            ptrdiff_t h_off = 0, v_off = 0;
1660
2.23k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
2.21k
                for (int pl = 0; pl < 2; pl++) {
1662
1.47k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.47k
                             NULL, f->cur.stride[1],
1664
1.47k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.47k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.47k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.47k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.47k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.47k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.47k
                    if (res) return res;
1671
1.47k
                }
1672
737
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
737
                h_off = 2;
1674
737
            }
1675
2.23k
            if (bw4 == 1) {
1676
1.54k
                const enum Filter2d left_filter_2d =
1677
1.54k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
4.62k
                for (int pl = 0; pl < 2; pl++) {
1679
3.08k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
3.08k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
3.08k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
3.08k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
3.08k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
3.08k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
3.08k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
3.08k
                    if (res) return res;
1687
3.08k
                }
1688
1.54k
                h_off = 2;
1689
1.54k
            }
1690
2.23k
            if (bh4 == ss_ver) {
1691
1.43k
                const enum Filter2d top_filter_2d =
1692
1.43k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
4.30k
                for (int pl = 0; pl < 2; pl++) {
1694
2.86k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
2.86k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
2.86k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
2.86k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
2.86k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
2.86k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
2.86k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
2.86k
                    if (res) return res;
1702
2.86k
                }
1703
1.43k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
1.43k
            }
1705
6.71k
            for (int pl = 0; pl < 2; pl++) {
1706
4.47k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
4.47k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
4.47k
                         refp, b->ref[0], filter_2d);
1709
4.47k
                if (res) return res;
1710
4.47k
            }
1711
128k
        } else {
1712
128k
            if (imin(cbw4, cbh4) > 1 &&
1713
79.8k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
79.6k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
1.61k
            {
1716
4.83k
                for (int pl = 0; pl < 2; pl++) {
1717
3.22k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
3.22k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
3.22k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
3.22k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
3.22k
                    if (res) return res;
1722
3.22k
                }
1723
126k
            } else {
1724
380k
                for (int pl = 0; pl < 2; pl++) {
1725
253k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
253k
                             NULL, f->cur.stride[1],
1727
253k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
253k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
253k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
253k
                    if (res) return res;
1731
253k
                    if (b->motion_mode == MM_OBMC) {
1732
60.7k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
60.7k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
60.7k
                        if (res) return res;
1735
60.7k
                    }
1736
253k
                }
1737
126k
            }
1738
128k
            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
9.36k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
28.1k
                for (int pl = 0; pl < 2; pl++) {
1745
18.7k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
18.7k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
18.7k
                    enum IntraPredMode m =
1748
18.7k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
15.9k
                        SMOOTH_PRED : b->interintra_mode;
1750
18.7k
                    int angle = 0;
1751
18.7k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
18.7k
                    const pixel *top_sb_edge = NULL;
1753
18.7k
                    if (!(t->by & (f->sb_step - 1))) {
1754
3.73k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
3.73k
                        const int sby = t->by >> f->sb_shift;
1756
3.73k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
3.73k
                    }
1758
18.7k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
18.7k
                                                          (t->bx >> ss_hor) >
1760
18.7k
                                                              (ts->tiling.col_start >> ss_hor),
1761
18.7k
                                                          t->by >> ss_ver,
1762
18.7k
                                                          (t->by >> ss_ver) >
1763
18.7k
                                                              (ts->tiling.row_start >> ss_ver),
1764
18.7k
                                                          ts->tiling.col_end >> ss_hor,
1765
18.7k
                                                          ts->tiling.row_end >> ss_ver,
1766
18.7k
                                                          0, uvdst, f->cur.stride[1],
1767
18.7k
                                                          top_sb_edge, m,
1768
18.7k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
18.7k
                                                          HIGHBD_CALL_SUFFIX);
1770
18.7k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
18.7k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
18.7k
                                             HIGHBD_CALL_SUFFIX);
1773
18.7k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
18.7k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
18.7k
                }
1776
9.36k
            }
1777
128k
        }
1778
1779
167k
    skip_inter_chroma_pred: {}
1780
167k
        t->tl_4x4_filter = filter_2d;
1781
167k
    } else {
1782
22.5k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
22.5k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
22.5k
        int jnt_weight;
1786
22.5k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
22.5k
        const uint8_t *mask;
1788
1789
67.6k
        for (int i = 0; i < 2; i++) {
1790
45.0k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
45.0k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
1.49k
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
1.49k
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
1.49k
                if (res) return res;
1796
43.5k
            } else {
1797
43.5k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
43.5k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
43.5k
                if (res) return res;
1800
43.5k
            }
1801
45.0k
        }
1802
22.5k
        switch (b->comp_type) {
1803
18.2k
        case COMP_INTER_AVG:
1804
18.2k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
18.2k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
18.2k
            break;
1807
1.61k
        case COMP_INTER_WEIGHTED_AVG:
1808
1.61k
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
1.61k
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
1.61k
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
1.61k
            break;
1812
2.02k
        case COMP_INTER_SEG:
1813
2.02k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
2.02k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
2.02k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
2.02k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
2.02k
            mask = seg_mask;
1818
2.02k
            break;
1819
701
        case COMP_INTER_WEDGE:
1820
701
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
701
            dsp->mc.mask(dst, f->cur.stride[0],
1822
701
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
701
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
701
            if (has_chroma)
1825
333
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
701
            break;
1827
22.5k
        }
1828
1829
        // chroma
1830
59.9k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
119k
            for (int i = 0; i < 2; i++) {
1832
79.8k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
79.8k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
11.5k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
1.90k
                {
1836
1.90k
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
1.90k
                                      b_dim, 1 + pl,
1838
1.90k
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
1.90k
                    if (res) return res;
1840
77.9k
                } else {
1841
77.9k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
77.9k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
77.9k
                    if (res) return res;
1844
77.9k
                }
1845
79.8k
            }
1846
39.9k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
39.9k
            switch (b->comp_type) {
1848
33.1k
            case COMP_INTER_AVG:
1849
33.1k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
33.1k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
33.1k
                            HIGHBD_CALL_SUFFIX);
1852
33.1k
                break;
1853
2.83k
            case COMP_INTER_WEIGHTED_AVG:
1854
2.83k
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
2.83k
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
2.83k
                              HIGHBD_CALL_SUFFIX);
1857
2.83k
                break;
1858
666
            case COMP_INTER_WEDGE:
1859
3.94k
            case COMP_INTER_SEG:
1860
3.94k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
3.94k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
3.94k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
3.94k
                             HIGHBD_CALL_SUFFIX);
1864
3.94k
                break;
1865
39.9k
            }
1866
39.9k
        }
1867
22.5k
    }
1868
1869
197k
    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
197k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
197k
    if (b->skip) {
1882
        // reset coef contexts
1883
92.5k
        BlockContext *const a = t->a;
1884
92.5k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
92.5k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
92.5k
        if (has_chroma) {
1887
67.4k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
67.4k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
67.4k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
67.4k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
67.4k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
67.4k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
67.4k
        }
1894
92.5k
        return 0;
1895
92.5k
    }
1896
1897
105k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
105k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
105k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
215k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
220k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
111k
            int y_off = !!init_y, y;
1905
111k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
232k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
121k
                 y += ytx->h, y_off++)
1908
121k
            {
1909
121k
                int x, x_off = !!init_x;
1910
287k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
166k
                     x += ytx->w, x_off++)
1912
166k
                {
1913
166k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
166k
                                   x_off, y_off, &dst[x * 4]);
1915
166k
                    t->bx += ytx->w;
1916
166k
                }
1917
121k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
121k
                t->bx -= x;
1919
121k
                t->by += ytx->h;
1920
121k
            }
1921
111k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
111k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
283k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
188k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
188k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
188k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
408k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
219k
                {
1931
219k
                    int x;
1932
219k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
541k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
321k
                    {
1935
321k
                        coef *cf;
1936
321k
                        int eob;
1937
321k
                        enum TxfmType txtp;
1938
321k
                        if (t->frame_thread.pass) {
1939
321k
                            const int p = t->frame_thread.pass & 1;
1940
321k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
321k
                            cf = ts->frame_thread[p].cf;
1942
321k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
321k
                            eob  = cbi >> 5;
1944
321k
                            txtp = cbi & 0x1f;
1945
321k
                        } 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
321k
                        if (eob >= 0) {
1964
113k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
113k
                            dsp->itx.itxfm_add[b->uvtx]
1967
113k
                                              [txtp](&uvdst[4 * x],
1968
113k
                                                     f->cur.stride[1],
1969
113k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
113k
                            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
113k
                        }
1974
321k
                        t->bx += uvtx->w << ss_hor;
1975
321k
                    }
1976
219k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
219k
                    t->bx -= x << ss_hor;
1978
219k
                    t->by += uvtx->h << ss_ver;
1979
219k
                }
1980
188k
                t->by -= y << ss_ver;
1981
188k
            }
1982
111k
        }
1983
109k
    }
1984
105k
    return 0;
1985
197k
}
1986
1987
117k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
117k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
117k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
117k
    const int y = sby * f->sb_step * 4;
1994
117k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
117k
    pixel *const p[3] = {
1996
117k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
117k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
117k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
117k
    };
2000
117k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
117k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
117k
                                        f->lf.start_of_tile_row[sby]);
2003
117k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
63.1k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
63.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
63.1k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
63.1k
    const int y = sby * f->sb_step * 4;
1994
63.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
63.1k
    pixel *const p[3] = {
1996
63.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
63.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
63.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
63.1k
    };
2000
63.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
63.1k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
63.1k
                                        f->lf.start_of_tile_row[sby]);
2003
63.1k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
54.1k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
54.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
54.1k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
54.1k
    const int y = sby * f->sb_step * 4;
1994
54.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
54.1k
    pixel *const p[3] = {
1996
54.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
54.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
54.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
54.1k
    };
2000
54.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
54.1k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
54.1k
                                        f->lf.start_of_tile_row[sby]);
2003
54.1k
}
2004
2005
128k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
128k
    const int y = sby * f->sb_step * 4;
2007
128k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
128k
    pixel *const p[3] = {
2009
128k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
128k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
128k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
128k
    };
2013
128k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
128k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
128k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
117k
    {
2017
117k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
117k
    }
2019
128k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
106k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
106k
    }
2023
128k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
69.6k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
69.6k
    const int y = sby * f->sb_step * 4;
2007
69.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
69.6k
    pixel *const p[3] = {
2009
69.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
69.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
69.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
69.6k
    };
2013
69.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
69.6k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
69.6k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
63.1k
    {
2017
63.1k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
63.1k
    }
2019
69.6k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
55.5k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
55.5k
    }
2023
69.6k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
58.6k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
58.6k
    const int y = sby * f->sb_step * 4;
2007
58.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
58.6k
    pixel *const p[3] = {
2009
58.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
58.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
58.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
58.6k
    };
2013
58.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
58.6k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
58.6k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
54.1k
    {
2017
54.1k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
54.1k
    }
2019
58.6k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
51.3k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
51.3k
    }
2023
58.6k
}
2024
2025
69.8k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
69.8k
    const Dav1dFrameContext *const f = tc->f;
2027
69.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
69.8k
    const int sbsz = f->sb_step;
2029
69.8k
    const int y = sby * sbsz * 4;
2030
69.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
69.8k
    pixel *const p[3] = {
2032
69.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
69.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
69.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
69.8k
    };
2036
69.8k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
69.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
69.8k
    const int start = sby * sbsz;
2039
69.8k
    if (sby) {
2040
34.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
34.7k
        pixel *p_up[3] = {
2042
34.7k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
34.7k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
34.7k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
34.7k
        };
2046
34.7k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
34.7k
    }
2048
69.8k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
69.8k
    const int end = imin(start + n_blks, f->bh);
2050
69.8k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
69.8k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
34.2k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
34.2k
    const Dav1dFrameContext *const f = tc->f;
2027
34.2k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
34.2k
    const int sbsz = f->sb_step;
2029
34.2k
    const int y = sby * sbsz * 4;
2030
34.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
34.2k
    pixel *const p[3] = {
2032
34.2k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
34.2k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
34.2k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
34.2k
    };
2036
34.2k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
34.2k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
34.2k
    const int start = sby * sbsz;
2039
34.2k
    if (sby) {
2040
20.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
20.1k
        pixel *p_up[3] = {
2042
20.1k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
20.1k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
20.1k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
20.1k
        };
2046
20.1k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
20.1k
    }
2048
34.2k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
34.2k
    const int end = imin(start + n_blks, f->bh);
2050
34.2k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
34.2k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
35.6k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
35.6k
    const Dav1dFrameContext *const f = tc->f;
2027
35.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
35.6k
    const int sbsz = f->sb_step;
2029
35.6k
    const int y = sby * sbsz * 4;
2030
35.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
35.6k
    pixel *const p[3] = {
2032
35.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
35.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
35.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
35.6k
    };
2036
35.6k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
35.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
35.6k
    const int start = sby * sbsz;
2039
35.6k
    if (sby) {
2040
14.6k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
14.6k
        pixel *p_up[3] = {
2042
14.6k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
14.6k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
14.6k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
14.6k
        };
2046
14.6k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
14.6k
    }
2048
35.6k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
35.6k
    const int end = imin(start + n_blks, f->bh);
2050
35.6k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
35.6k
}
2052
2053
17.1k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
17.1k
    const int sbsz = f->sb_step;
2055
17.1k
    const int y = sby * sbsz * 4;
2056
17.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
17.1k
    const pixel *const p[3] = {
2058
17.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
17.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
17.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
17.1k
    };
2062
17.1k
    pixel *const sr_p[3] = {
2063
17.1k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
17.1k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
17.1k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
17.1k
    };
2067
17.1k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
61.6k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
44.5k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
44.5k
        const int h_start = 8 * !!sby >> ss_ver;
2071
44.5k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
44.5k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
44.5k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
44.5k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
44.5k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
44.5k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
44.5k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
44.5k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
44.5k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
44.5k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
44.5k
                          imin(img_h, h_end) + h_start, src_w,
2083
44.5k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
44.5k
                          HIGHBD_CALL_SUFFIX);
2085
44.5k
    }
2086
17.1k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
9.17k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
9.17k
    const int sbsz = f->sb_step;
2055
9.17k
    const int y = sby * sbsz * 4;
2056
9.17k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
9.17k
    const pixel *const p[3] = {
2058
9.17k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
9.17k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
9.17k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
9.17k
    };
2062
9.17k
    pixel *const sr_p[3] = {
2063
9.17k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
9.17k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
9.17k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
9.17k
    };
2067
9.17k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
31.6k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
22.4k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
22.4k
        const int h_start = 8 * !!sby >> ss_ver;
2071
22.4k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
22.4k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
22.4k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
22.4k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
22.4k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
22.4k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
22.4k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
22.4k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
22.4k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
22.4k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
22.4k
                          imin(img_h, h_end) + h_start, src_w,
2083
22.4k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
22.4k
                          HIGHBD_CALL_SUFFIX);
2085
22.4k
    }
2086
9.17k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
7.99k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
7.99k
    const int sbsz = f->sb_step;
2055
7.99k
    const int y = sby * sbsz * 4;
2056
7.99k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
7.99k
    const pixel *const p[3] = {
2058
7.99k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
7.99k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
7.99k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
7.99k
    };
2062
7.99k
    pixel *const sr_p[3] = {
2063
7.99k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
7.99k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
7.99k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
7.99k
    };
2067
7.99k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
30.0k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
22.0k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
22.0k
        const int h_start = 8 * !!sby >> ss_ver;
2071
22.0k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
22.0k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
22.0k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
22.0k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
22.0k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
22.0k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
22.0k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
22.0k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
22.0k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
22.0k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
22.0k
                          imin(img_h, h_end) + h_start, src_w,
2083
22.0k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
22.0k
                          HIGHBD_CALL_SUFFIX);
2085
22.0k
    }
2086
7.99k
}
2087
2088
81.1k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
81.1k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
81.1k
    const int y = sby * f->sb_step * 4;
2091
81.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
81.1k
    pixel *const sr_p[3] = {
2093
81.1k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
81.1k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
81.1k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
81.1k
    };
2097
81.1k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
81.1k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
44.6k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
44.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
44.6k
    const int y = sby * f->sb_step * 4;
2091
44.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
44.6k
    pixel *const sr_p[3] = {
2093
44.6k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
44.6k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
44.6k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
44.6k
    };
2097
44.6k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
44.6k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
36.5k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
36.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
36.5k
    const int y = sby * f->sb_step * 4;
2091
36.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
36.5k
    pixel *const sr_p[3] = {
2093
36.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
36.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
36.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
36.5k
    };
2097
36.5k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
36.5k
}
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
138k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
138k
    const Dav1dFrameContext *const f = t->f;
2113
138k
    Dav1dTileState *const ts = t->ts;
2114
138k
    const int sby = t->by >> f->sb_shift;
2115
138k
    const int sby_off = f->sb128w * 128 * sby;
2116
138k
    const int x_off = ts->tiling.col_start;
2117
2118
138k
    const pixel *const y =
2119
138k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
138k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
138k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
138k
               4 * (ts->tiling.col_end - x_off));
2123
2124
138k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
109k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
109k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
109k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
109k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
328k
        for (int pl = 1; pl <= 2; pl++)
2131
218k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
119k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
119k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
109k
    }
2135
138k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
74.7k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
74.7k
    const Dav1dFrameContext *const f = t->f;
2113
74.7k
    Dav1dTileState *const ts = t->ts;
2114
74.7k
    const int sby = t->by >> f->sb_shift;
2115
74.7k
    const int sby_off = f->sb128w * 128 * sby;
2116
74.7k
    const int x_off = ts->tiling.col_start;
2117
2118
74.7k
    const pixel *const y =
2119
74.7k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
74.7k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
74.7k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
74.7k
               4 * (ts->tiling.col_end - x_off));
2123
2124
74.7k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
59.5k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
59.5k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
59.5k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
59.5k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
178k
        for (int pl = 1; pl <= 2; pl++)
2131
119k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
119k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
119k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
59.5k
    }
2135
74.7k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
64.2k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
64.2k
    const Dav1dFrameContext *const f = t->f;
2113
64.2k
    Dav1dTileState *const ts = t->ts;
2114
64.2k
    const int sby = t->by >> f->sb_shift;
2115
64.2k
    const int sby_off = f->sb128w * 128 * sby;
2116
64.2k
    const int x_off = ts->tiling.col_start;
2117
2118
64.2k
    const pixel *const y =
2119
64.2k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
64.2k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
64.2k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
64.2k
               4 * (ts->tiling.col_end - x_off));
2123
2124
64.2k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
49.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
49.8k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
49.8k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
49.8k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
149k
        for (int pl = 1; pl <= 2; pl++)
2131
99.6k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
49.8k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
49.8k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
49.8k
    }
2135
64.2k
}
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
19.0k
{
2142
19.0k
    const Dav1dFrameContext *const f = t->f;
2143
19.0k
    pixel *const pal = t->frame_thread.pass ?
2144
19.0k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
19.0k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
19.0k
        bytefn(t->scratch.pal)[0];
2147
93.2k
    for (int x = 0; x < bw4; x++)
2148
74.1k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
81.2k
    for (int y = 0; y < bh4; y++)
2150
62.1k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
19.0k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
6.66k
{
2142
6.66k
    const Dav1dFrameContext *const f = t->f;
2143
6.66k
    pixel *const pal = t->frame_thread.pass ?
2144
6.66k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
6.66k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
6.66k
        bytefn(t->scratch.pal)[0];
2147
31.3k
    for (int x = 0; x < bw4; x++)
2148
24.6k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
28.9k
    for (int y = 0; y < bh4; y++)
2150
22.3k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
6.66k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
12.4k
{
2142
12.4k
    const Dav1dFrameContext *const f = t->f;
2143
12.4k
    pixel *const pal = t->frame_thread.pass ?
2144
12.4k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
12.4k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
12.4k
        bytefn(t->scratch.pal)[0];
2147
61.9k
    for (int x = 0; x < bw4; x++)
2148
49.4k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
52.2k
    for (int y = 0; y < bh4; y++)
2150
39.8k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
12.4k
}
2152
2153
void bytefn(dav1d_copy_pal_block_uv)(Dav1dTaskContext *const t,
2154
                                     const int bx4, const int by4,
2155
                                     const int bw4, const int bh4)
2156
2157
4.88k
{
2158
4.88k
    const Dav1dFrameContext *const f = t->f;
2159
4.88k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
4.88k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
4.88k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
4.88k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
14.6k
    for (int pl = 1; pl <= 2; pl++) {
2165
54.3k
        for (int x = 0; x < bw4; x++)
2166
44.6k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
50.7k
        for (int y = 0; y < bh4; y++)
2168
40.9k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
9.76k
    }
2170
4.88k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
1.78k
{
2158
1.78k
    const Dav1dFrameContext *const f = t->f;
2159
1.78k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
1.78k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
1.78k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
1.78k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
5.34k
    for (int pl = 1; pl <= 2; pl++) {
2165
20.3k
        for (int x = 0; x < bw4; x++)
2166
16.8k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
20.0k
        for (int y = 0; y < bh4; y++)
2168
16.5k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
3.56k
    }
2170
1.78k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
3.10k
{
2158
3.10k
    const Dav1dFrameContext *const f = t->f;
2159
3.10k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
3.10k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
3.10k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
3.10k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
9.30k
    for (int pl = 1; pl <= 2; pl++) {
2165
34.0k
        for (int x = 0; x < bw4; x++)
2166
27.8k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
30.6k
        for (int y = 0; y < bh4; y++)
2168
24.4k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
6.20k
    }
2170
3.10k
}
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
23.9k
{
2176
23.9k
    Dav1dTileState *const ts = t->ts;
2177
23.9k
    const Dav1dFrameContext *const f = t->f;
2178
23.9k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
23.9k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
23.9k
    pixel cache[16], used_cache[8];
2181
23.9k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
23.9k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
23.9k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
23.9k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
23.9k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
45.1k
    while (l_cache && a_cache) {
2190
21.1k
        if (*l < *a) {
2191
8.11k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
8.07k
                cache[n_cache++] = *l;
2193
8.11k
            l++;
2194
8.11k
            l_cache--;
2195
13.0k
        } else {
2196
13.0k
            if (*a == *l) {
2197
5.15k
                l++;
2198
5.15k
                l_cache--;
2199
5.15k
            }
2200
13.0k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
12.6k
                cache[n_cache++] = *a;
2202
13.0k
            a++;
2203
13.0k
            a_cache--;
2204
13.0k
        }
2205
21.1k
    }
2206
23.9k
    if (l_cache) {
2207
32.5k
        do {
2208
32.5k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
26.5k
                cache[n_cache++] = *l;
2210
32.5k
            l++;
2211
32.5k
        } while (--l_cache > 0);
2212
16.1k
    } else if (a_cache) {
2213
24.0k
        do {
2214
24.0k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
18.9k
                cache[n_cache++] = *a;
2216
24.0k
            a++;
2217
24.0k
        } while (--a_cache > 0);
2218
5.88k
    }
2219
2220
    // find reused cache entries
2221
23.9k
    int i = 0;
2222
82.4k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
58.4k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
29.0k
            used_cache[i++] = cache[n];
2225
23.9k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
23.9k
    pixel *const pal = t->frame_thread.pass ?
2229
23.9k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
23.9k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
23.9k
        bytefn(t->scratch.pal)[pl];
2232
23.9k
    if (i < pal_sz) {
2233
20.3k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
20.3k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
20.3k
        if (i < pal_sz) {
2237
18.1k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
18.1k
            const int max = (1 << bpc) - 1;
2239
2240
41.9k
            do {
2241
41.9k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
41.9k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
41.9k
                if (prev + !pl >= max) {
2244
24.5k
                    for (; i < pal_sz; i++)
2245
15.9k
                        pal[i] = max;
2246
8.55k
                    break;
2247
8.55k
                }
2248
33.3k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
33.3k
            } while (i < pal_sz);
2250
18.1k
        }
2251
2252
        // merge cache+new entries
2253
20.3k
        int n = 0, m = n_used_cache;
2254
117k
        for (i = 0; i < pal_sz; i++) {
2255
97.3k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
19.1k
                pal[i] = used_cache[n++];
2257
78.2k
            } else {
2258
78.2k
                assert(m < pal_sz);
2259
78.2k
                pal[i] = pal[m++];
2260
78.2k
            }
2261
97.3k
        }
2262
20.3k
    } else {
2263
3.63k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
3.63k
    }
2265
2266
23.9k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
23.9k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
8.45k
{
2176
8.45k
    Dav1dTileState *const ts = t->ts;
2177
8.45k
    const Dav1dFrameContext *const f = t->f;
2178
8.45k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
8.45k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
8.45k
    pixel cache[16], used_cache[8];
2181
8.45k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
8.45k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
8.45k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
8.45k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
8.45k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
13.7k
    while (l_cache && a_cache) {
2190
5.28k
        if (*l < *a) {
2191
2.01k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
1.97k
                cache[n_cache++] = *l;
2193
2.01k
            l++;
2194
2.01k
            l_cache--;
2195
3.27k
        } else {
2196
3.27k
            if (*a == *l) {
2197
1.43k
                l++;
2198
1.43k
                l_cache--;
2199
1.43k
            }
2200
3.27k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
3.10k
                cache[n_cache++] = *a;
2202
3.27k
            a++;
2203
3.27k
            a_cache--;
2204
3.27k
        }
2205
5.28k
    }
2206
8.45k
    if (l_cache) {
2207
10.4k
        do {
2208
10.4k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
8.10k
                cache[n_cache++] = *l;
2210
10.4k
            l++;
2211
10.4k
        } while (--l_cache > 0);
2212
6.02k
    } else if (a_cache) {
2213
7.21k
        do {
2214
7.21k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
5.50k
                cache[n_cache++] = *a;
2216
7.21k
            a++;
2217
7.21k
        } while (--a_cache > 0);
2218
1.72k
    }
2219
2220
    // find reused cache entries
2221
8.45k
    int i = 0;
2222
25.2k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
16.8k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
8.34k
            used_cache[i++] = cache[n];
2225
8.45k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
8.45k
    pixel *const pal = t->frame_thread.pass ?
2229
8.45k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
8.45k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
8.45k
        bytefn(t->scratch.pal)[pl];
2232
8.45k
    if (i < pal_sz) {
2233
7.50k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
7.50k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
7.50k
        if (i < pal_sz) {
2237
6.76k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
6.76k
            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
10.2k
                    for (; i < pal_sz; i++)
2245
6.79k
                        pal[i] = max;
2246
3.42k
                    break;
2247
3.42k
                }
2248
11.7k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
11.7k
            } while (i < pal_sz);
2250
6.76k
        }
2251
2252
        // merge cache+new entries
2253
7.50k
        int n = 0, m = n_used_cache;
2254
42.8k
        for (i = 0; i < pal_sz; i++) {
2255
35.3k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
5.83k
                pal[i] = used_cache[n++];
2257
29.5k
            } else {
2258
29.5k
                assert(m < pal_sz);
2259
29.5k
                pal[i] = pal[m++];
2260
29.5k
            }
2261
35.3k
        }
2262
7.50k
    } else {
2263
942
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
942
    }
2265
2266
8.45k
    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
8.45k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
15.5k
{
2176
15.5k
    Dav1dTileState *const ts = t->ts;
2177
15.5k
    const Dav1dFrameContext *const f = t->f;
2178
15.5k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
15.5k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
15.5k
    pixel cache[16], used_cache[8];
2181
15.5k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
15.5k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
15.5k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
15.5k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
15.5k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
31.4k
    while (l_cache && a_cache) {
2190
15.8k
        if (*l < *a) {
2191
6.10k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
6.09k
                cache[n_cache++] = *l;
2193
6.10k
            l++;
2194
6.10k
            l_cache--;
2195
9.78k
        } else {
2196
9.78k
            if (*a == *l) {
2197
3.71k
                l++;
2198
3.71k
                l_cache--;
2199
3.71k
            }
2200
9.78k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
9.52k
                cache[n_cache++] = *a;
2202
9.78k
            a++;
2203
9.78k
            a_cache--;
2204
9.78k
        }
2205
15.8k
    }
2206
15.5k
    if (l_cache) {
2207
22.1k
        do {
2208
22.1k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
18.4k
                cache[n_cache++] = *l;
2210
22.1k
            l++;
2211
22.1k
        } while (--l_cache > 0);
2212
10.1k
    } else if (a_cache) {
2213
16.8k
        do {
2214
16.8k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
13.4k
                cache[n_cache++] = *a;
2216
16.8k
            a++;
2217
16.8k
        } while (--a_cache > 0);
2218
4.15k
    }
2219
2220
    // find reused cache entries
2221
15.5k
    int i = 0;
2222
57.1k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
41.6k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
20.6k
            used_cache[i++] = cache[n];
2225
15.5k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
15.5k
    pixel *const pal = t->frame_thread.pass ?
2229
15.5k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
15.5k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
15.5k
        bytefn(t->scratch.pal)[pl];
2232
15.5k
    if (i < pal_sz) {
2233
12.8k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
12.8k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
12.8k
        if (i < pal_sz) {
2237
11.3k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
11.3k
            const int max = (1 << bpc) - 1;
2239
2240
26.7k
            do {
2241
26.7k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
26.7k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
26.7k
                if (prev + !pl >= max) {
2244
14.2k
                    for (; i < pal_sz; i++)
2245
9.16k
                        pal[i] = max;
2246
5.12k
                    break;
2247
5.12k
                }
2248
21.5k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
21.5k
            } while (i < pal_sz);
2250
11.3k
        }
2251
2252
        // merge cache+new entries
2253
12.8k
        int n = 0, m = n_used_cache;
2254
74.8k
        for (i = 0; i < pal_sz; i++) {
2255
62.0k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
13.3k
                pal[i] = used_cache[n++];
2257
48.7k
            } else {
2258
48.7k
                assert(m < pal_sz);
2259
48.7k
                pal[i] = pal[m++];
2260
48.7k
            }
2261
62.0k
        }
2262
12.8k
    } else {
2263
2.69k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
2.69k
    }
2265
2266
15.5k
    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.5k
}
2277
2278
void bytefn(dav1d_read_pal_uv)(Dav1dTaskContext *const t, Av1Block *const b,
2279
                               const int sz_ctx, const int bx4, const int by4)
2280
4.88k
{
2281
4.88k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
4.88k
    Dav1dTileState *const ts = t->ts;
2285
4.88k
    const Dav1dFrameContext *const f = t->f;
2286
4.88k
    pixel *const pal = t->frame_thread.pass ?
2287
4.88k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
4.88k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
4.88k
        bytefn(t->scratch.pal)[2];
2290
4.88k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
4.88k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
2.35k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
2.35k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
2.35k
        const int max = (1 << bpc) - 1;
2295
9.81k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
7.45k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
7.45k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
7.45k
            prev = pal[i] = (prev + delta) & max;
2299
7.45k
        }
2300
2.53k
    } else {
2301
12.7k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
10.2k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
2.53k
    }
2304
4.88k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
4.88k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
1.78k
{
2281
1.78k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
1.78k
    Dav1dTileState *const ts = t->ts;
2285
1.78k
    const Dav1dFrameContext *const f = t->f;
2286
1.78k
    pixel *const pal = t->frame_thread.pass ?
2287
1.78k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
1.78k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
1.78k
        bytefn(t->scratch.pal)[2];
2290
1.78k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
1.78k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
856
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
856
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
856
        const int max = (1 << bpc) - 1;
2295
3.68k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
2.83k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
2.83k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
2.83k
            prev = pal[i] = (prev + delta) & max;
2299
2.83k
        }
2300
927
    } else {
2301
4.73k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
3.80k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
927
    }
2304
1.78k
    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.78k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
3.10k
{
2281
3.10k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
3.10k
    Dav1dTileState *const ts = t->ts;
2285
3.10k
    const Dav1dFrameContext *const f = t->f;
2286
3.10k
    pixel *const pal = t->frame_thread.pass ?
2287
3.10k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
3.10k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
3.10k
        bytefn(t->scratch.pal)[2];
2290
3.10k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
3.10k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.49k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.49k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.49k
        const int max = (1 << bpc) - 1;
2295
6.12k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
4.62k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
4.62k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
4.62k
            prev = pal[i] = (prev + delta) & max;
2299
4.62k
        }
2300
1.60k
    } else {
2301
8.06k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
6.45k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.60k
    }
2304
3.10k
    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.10k
}