Coverage Report

Created: 2026-09-14 06:44

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