Coverage Report

Created: 2026-09-14 06:39

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