Coverage Report

Created: 2026-10-28 06:13

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
298k
static inline unsigned read_golomb(MsacContext *const msac) {
50
298k
    int len = 0;
51
298k
    unsigned val = 1;
52
53
528k
    while (!dav1d_msac_decode_bool_equi(msac) && len < 32) len++;
54
528k
    while (len--) val = (val << 1) + dav1d_msac_decode_bool_equi(msac);
55
56
298k
    return val - 1;
57
298k
}
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.32M
{
66
2.32M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
67
68
2.32M
    if (chroma) {
69
1.30M
        const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
70
1.30M
        const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
71
1.30M
        const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
72
803k
                                b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
73
1.30M
        unsigned ca, cl;
74
75
1.30M
#define MERGE_CTX(dir, type, no_val) \
76
2.60M
        c##dir = *(const type *) dir != no_val; \
77
2.60M
        break
78
79
1.30M
        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
280k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  0x40);
87
255k
        case TX_8X8:   MERGE_CTX(a, uint16_t, 0x4040);
88
229k
        case TX_16X16: MERGE_CTX(a, uint32_t, 0x40404040U);
89
534k
        case TX_32X32: MERGE_CTX(a, uint64_t, 0x4040404040404040ULL);
90
1.30M
        }
91
1.30M
        switch (t_dim->lh) {
92
0
        default: assert(0); /* fall-through */
93
314k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  0x40);
94
264k
        case TX_8X8:   MERGE_CTX(l, uint16_t, 0x4040);
95
195k
        case TX_16X16: MERGE_CTX(l, uint32_t, 0x40404040U);
96
526k
        case TX_32X32: MERGE_CTX(l, uint64_t, 0x4040404040404040ULL);
97
1.30M
        }
98
1.30M
#undef MERGE_CTX
99
100
1.30M
        return 7 + not_one_blk * 3 + ca + cl;
101
1.30M
    } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
102
484k
        return 0;
103
544k
    } else {
104
544k
        unsigned la, ll;
105
106
544k
#define MERGE_CTX(dir, type, tx) \
107
1.09M
        if (tx == TX_64X64) { \
108
135k
            uint64_t tmp = *(const uint64_t *) dir; \
109
135k
            tmp |= *(const uint64_t *) &dir[8]; \
110
135k
            l##dir = (unsigned) (tmp >> 32) | (unsigned) tmp; \
111
135k
        } else \
112
1.09M
            l##dir = *(const type *) dir; \
113
1.09M
        if (tx == TX_32X32) l##dir |= *(const type *) &dir[sizeof(type)]; \
114
1.09M
        if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
115
1.09M
        if (tx >= TX_8X8)   l##dir |= l##dir >> 8; \
116
1.09M
        break
117
118
544k
        switch (t_dim->lw) {
119
0
        default: assert(0); /* fall-through */
120
233k
        case TX_4X4:   MERGE_CTX(a, uint8_t,  TX_4X4);
121
127k
        case TX_8X8:   MERGE_CTX(a, uint16_t, TX_8X8);
122
106k
        case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
123
10.5k
        case TX_32X32: MERGE_CTX(a, uint32_t, TX_32X32);
124
67.9k
        case TX_64X64: MERGE_CTX(a, uint32_t, TX_64X64);
125
544k
        }
126
545k
        switch (t_dim->lh) {
127
0
        default: assert(0); /* fall-through */
128
237k
        case TX_4X4:   MERGE_CTX(l, uint8_t,  TX_4X4);
129
124k
        case TX_8X8:   MERGE_CTX(l, uint16_t, TX_8X8);
130
105k
        case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
131
10.4k
        case TX_32X32: MERGE_CTX(l, uint32_t, TX_32X32);
132
67.9k
        case TX_64X64: MERGE_CTX(l, uint32_t, TX_64X64);
133
545k
        }
134
545k
#undef MERGE_CTX
135
136
545k
        return dav1d_skip_ctx[umin(la & 0x3F, 4)][umin(ll & 0x3F, 4)];
137
545k
    }
138
2.32M
}
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
891k
{
144
891k
    uint64_t mask = 0xC0C0C0C0C0C0C0C0ULL, mul = 0x0101010101010101ULL;
145
891k
    int s;
146
147
891k
#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
891k
    __asm__("" : "+r"(mask), "+r"(mul));
151
891k
#endif
152
153
891k
    switch(tx) {
154
0
    default: assert(0); /* fall-through */
155
184k
    case TX_4X4: {
156
184k
        int t = *(const uint8_t *) a >> 6;
157
184k
        t    += *(const uint8_t *) l >> 6;
158
184k
        s = t - 1 - 1;
159
184k
        break;
160
0
    }
161
112k
    case TX_8X8: {
162
112k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
163
112k
        t         += *(const uint16_t *) l & (uint32_t) mask;
164
112k
        t *= 0x04040404U;
165
112k
        s = (int) (t >> 24) - 2 - 2;
166
112k
        break;
167
0
    }
168
89.0k
    case TX_16X16: {
169
89.0k
        uint32_t t = (*(const uint32_t *) a & (uint32_t) mask) >> 6;
170
89.0k
        t         += (*(const uint32_t *) l & (uint32_t) mask) >> 6;
171
89.0k
        t *= (uint32_t) mul;
172
89.0k
        s = (int) (t >> 24) - 4 - 4;
173
89.0k
        break;
174
0
    }
175
133k
    case TX_32X32: {
176
133k
        uint64_t t = (*(const uint64_t *) a & mask) >> 6;
177
133k
        t         += (*(const uint64_t *) l & mask) >> 6;
178
133k
        t *= mul;
179
133k
        s = (int) (t >> 56) - 8 - 8;
180
133k
        break;
181
0
    }
182
42.4k
    case TX_64X64: {
183
42.4k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
184
42.4k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
185
42.4k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
186
42.4k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
187
42.4k
        t *= mul;
188
42.4k
        s = (int) (t >> 56) - 16 - 16;
189
42.4k
        break;
190
0
    }
191
33.4k
    case RTX_4X8: {
192
33.4k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
193
33.4k
        t         += *(const uint16_t *) l & (uint32_t) mask;
194
33.4k
        t *= 0x04040404U;
195
33.4k
        s = (int) (t >> 24) - 1 - 2;
196
33.4k
        break;
197
0
    }
198
44.9k
    case RTX_8X4: {
199
44.9k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
200
44.9k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
201
44.9k
        t *= 0x04040404U;
202
44.9k
        s = (int) (t >> 24) - 2 - 1;
203
44.9k
        break;
204
0
    }
205
41.4k
    case RTX_8X16: {
206
41.4k
        uint32_t t = *(const uint16_t *) a & (uint32_t) mask;
207
41.4k
        t         += *(const uint32_t *) l & (uint32_t) mask;
208
41.4k
        t = (t >> 6) * (uint32_t) mul;
209
41.4k
        s = (int) (t >> 24) - 2 - 4;
210
41.4k
        break;
211
0
    }
212
52.9k
    case RTX_16X8: {
213
52.9k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
214
52.9k
        t         += *(const uint16_t *) l & (uint32_t) mask;
215
52.9k
        t = (t >> 6) * (uint32_t) mul;
216
52.9k
        s = (int) (t >> 24) - 4 - 2;
217
52.9k
        break;
218
0
    }
219
25.1k
    case RTX_16X32: {
220
25.1k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
221
25.1k
        t         += *(const uint64_t *) l & mask;
222
25.1k
        t = (t >> 6) * mul;
223
25.1k
        s = (int) (t >> 56) - 4 - 8;
224
25.1k
        break;
225
0
    }
226
24.0k
    case RTX_32X16: {
227
24.0k
        uint64_t t = *(const uint64_t *) a & mask;
228
24.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
229
24.0k
        t = (t >> 6) * mul;
230
24.0k
        s = (int) (t >> 56) - 8 - 4;
231
24.0k
        break;
232
0
    }
233
8.83k
    case RTX_32X64: {
234
8.83k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
235
8.83k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
236
8.83k
        t         += (*(const uint64_t *) &l[8] & mask) >> 6;
237
8.83k
        t *= mul;
238
8.83k
        s = (int) (t >> 56) - 8 - 16;
239
8.83k
        break;
240
0
    }
241
7.33k
    case RTX_64X32: {
242
7.33k
        uint64_t t = (*(const uint64_t *) &a[0] & mask) >> 6;
243
7.33k
        t         += (*(const uint64_t *) &a[8] & mask) >> 6;
244
7.33k
        t         += (*(const uint64_t *) &l[0] & mask) >> 6;
245
7.33k
        t *= mul;
246
7.33k
        s = (int) (t >> 56) - 16 - 8;
247
7.33k
        break;
248
0
    }
249
16.0k
    case RTX_4X16: {
250
16.0k
        uint32_t t = *(const uint8_t  *) a & (uint32_t) mask;
251
16.0k
        t         += *(const uint32_t *) l & (uint32_t) mask;
252
16.0k
        t = (t >> 6) * (uint32_t) mul;
253
16.0k
        s = (int) (t >> 24) - 1 - 4;
254
16.0k
        break;
255
0
    }
256
37.8k
    case RTX_16X4: {
257
37.8k
        uint32_t t = *(const uint32_t *) a & (uint32_t) mask;
258
37.8k
        t         += *(const uint8_t  *) l & (uint32_t) mask;
259
37.8k
        t = (t >> 6) * (uint32_t) mul;
260
37.8k
        s = (int) (t >> 24) - 4 - 1;
261
37.8k
        break;
262
0
    }
263
12.0k
    case RTX_8X32: {
264
12.0k
        uint64_t t = *(const uint16_t *) a & (uint32_t) mask;
265
12.0k
        t         += *(const uint64_t *) l & mask;
266
12.0k
        t = (t >> 6) * mul;
267
12.0k
        s = (int) (t >> 56) - 2 - 8;
268
12.0k
        break;
269
0
    }
270
17.9k
    case RTX_32X8: {
271
17.9k
        uint64_t t = *(const uint64_t *) a & mask;
272
17.9k
        t         += *(const uint16_t *) l & (uint32_t) mask;
273
17.9k
        t = (t >> 6) * mul;
274
17.9k
        s = (int) (t >> 56) - 8 - 2;
275
17.9k
        break;
276
0
    }
277
2.99k
    case RTX_16X64: {
278
2.99k
        uint64_t t = *(const uint32_t *) a & (uint32_t) mask;
279
2.99k
        t         += *(const uint64_t *) &l[0] & mask;
280
2.99k
        t = (t >> 6) + ((*(const uint64_t *) &l[8] & mask) >> 6);
281
2.99k
        t *= mul;
282
2.99k
        s = (int) (t >> 56) - 4 - 16;
283
2.99k
        break;
284
0
    }
285
4.42k
    case RTX_64X16: {
286
4.42k
        uint64_t t = *(const uint64_t *) &a[0] & mask;
287
4.42k
        t         += *(const uint32_t *) l & (uint32_t) mask;
288
4.42k
        t = (t >> 6) + ((*(const uint64_t *) &a[8] & mask) >> 6);
289
4.42k
        t *= mul;
290
4.42k
        s = (int) (t >> 56) - 16 - 4;
291
4.42k
        break;
292
0
    }
293
891k
    }
294
295
891k
    return (s != 0) + (s > 0);
296
891k
}
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
28.1M
{
305
28.1M
    unsigned mag = levels[0 * stride + 1] + levels[1 * stride + 0];
306
28.1M
    unsigned offset;
307
28.1M
    if (tx_class == TX_CLASS_2D) {
308
26.5M
        mag += levels[1 * stride + 1];
309
26.5M
        *hi_mag = mag;
310
26.5M
        mag += levels[0 * stride + 2] + levels[2 * stride + 0];
311
26.5M
        offset = ctx_offsets[umin(y, 4)][umin(x, 4)];
312
26.5M
    } else {
313
1.58M
        mag += levels[0 * stride + 2];
314
1.58M
        *hi_mag = mag;
315
1.58M
        mag += levels[0 * stride + 3] + levels[0 * stride + 4];
316
1.58M
        offset = 26 + (y > 1 ? 10 : y * 5);
317
1.58M
    }
318
28.1M
    return offset + (mag > 512 ? 4 : (mag + 64) >> 7);
319
28.1M
}
320
321
static int decode_coefs(Dav1dTaskContext *const t,
322
                        uint8_t *const a, uint8_t *const l,
323
                        const enum RectTxfmSize tx, const enum BlockSize bs,
324
                        const Av1Block *const b, const int intra,
325
                        const int plane, coef *cf,
326
                        enum TxfmType *const txtp, uint8_t *res_ctx)
327
2.32M
{
328
2.32M
    Dav1dTileState *const ts = t->ts;
329
2.32M
    const int chroma = !!plane;
330
2.32M
    const Dav1dFrameContext *const f = t->f;
331
2.32M
    const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
332
2.32M
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
333
2.32M
    const int dbg = DEBUG_BLOCK_INFO && plane && 0;
334
335
2.32M
    if (dbg)
336
0
        printf("Start: r=%d\n", ts->msac.rng);
337
338
    // does this block have any non-zero coefficients
339
2.32M
    const int sctx = get_skip_ctx(t_dim, bs, a, l, chroma, f->cur.p.layout);
340
2.32M
    const int all_skip = dav1d_msac_decode_bool_adapt(&ts->msac,
341
2.32M
                             ts->cdf.coef.skip[t_dim->ctx][sctx]);
342
2.32M
    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.32M
    if (all_skip) {
346
1.20M
        *res_ctx = 0x40;
347
1.20M
        *txtp = lossless * WHT_WHT; /* lossless ? WHT_WHT : DCT_DCT */
348
1.20M
        return -1;
349
1.20M
    }
350
351
    // transform type (chroma: derived, luma: explicitly coded)
352
1.12M
    if (lossless) {
353
123k
        assert(t_dim->max == TX_4X4);
354
123k
        *txtp = WHT_WHT;
355
999k
    } else if (t_dim->max + intra >= TX_64X64) {
356
267k
        *txtp = DCT_DCT;
357
731k
    } else if (chroma) {
358
        // inferred from either the luma txtp (inter) or a LUT (intra)
359
214k
        *txtp = intra ? dav1d_txtp_from_uvmode[b->uv_mode] :
360
214k
                        get_uv_inter_txtp(t_dim, *txtp);
361
517k
    } else if (!f->frame_hdr->segmentation.qidx[b->seg_id]) {
362
        // In libaom, lossless is checked by a literal qidx == 0, but not all
363
        // such blocks are actually lossless. The remainder gets an implicit
364
        // transform type (for luma)
365
5.46k
        *txtp = DCT_DCT;
366
512k
    } else {
367
512k
        unsigned idx;
368
512k
        if (intra) {
369
319k
            const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
370
285k
                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
371
319k
            if (f->frame_hdr->reduced_txtp_set || t_dim->min == TX_16X16) {
372
147k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
373
147k
                          ts->cdf.m.txtp_intra2[t_dim->min][y_mode_nofilt], 4);
374
147k
                *txtp = dav1d_tx_types_per_set[idx + 0];
375
172k
            } else {
376
172k
                idx = dav1d_msac_decode_symbol_adapt8(&ts->msac,
377
172k
                          ts->cdf.m.txtp_intra1[t_dim->min][y_mode_nofilt], 6);
378
172k
                *txtp = dav1d_tx_types_per_set[idx + 5];
379
172k
            }
380
319k
            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
319k
        } else {
384
192k
            if (f->frame_hdr->reduced_txtp_set || t_dim->max == TX_32X32) {
385
67.0k
                idx = dav1d_msac_decode_bool_adapt(&ts->msac,
386
67.0k
                          ts->cdf.m.txtp_inter3[t_dim->min]);
387
67.0k
                *txtp = (idx - 1) & IDTX; /* idx ? DCT_DCT : IDTX */
388
125k
            } else if (t_dim->min == TX_16X16) {
389
18.5k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
390
18.5k
                          ts->cdf.m.txtp_inter2, 11);
391
18.5k
                *txtp = dav1d_tx_types_per_set[idx + 12];
392
107k
            } else {
393
107k
                idx = dav1d_msac_decode_symbol_adapt16(&ts->msac,
394
107k
                          ts->cdf.m.txtp_inter1[t_dim->min], 15);
395
107k
                *txtp = dav1d_tx_types_per_set[idx + 24];
396
107k
            }
397
192k
            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
192k
        }
401
512k
    }
402
403
    // find end-of-block (eob)
404
1.12M
    int eob;
405
1.12M
    const int slw = imin(t_dim->lw, TX_32X32), slh = imin(t_dim->lh, TX_32X32);
406
1.12M
    const int tx2dszctx = slw + slh;
407
1.12M
    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
408
1.12M
    const int is_1d = tx_class != TX_CLASS_2D;
409
1.12M
    switch (tx2dszctx) {
410
0
#define case_sz(sz, bin, ns, is_1d) \
411
1.12M
    case sz: { \
412
1.12M
        uint16_t *const eob_bin_cdf = ts->cdf.coef.eob_bin_##bin[chroma]is_1d; \
413
1.12M
        eob = dav1d_msac_decode_symbol_adapt##ns(&ts->msac, eob_bin_cdf, 4 + sz); \
414
1.12M
        break; \
415
1.12M
    }
416
222k
    case_sz(0,   16,  8, [is_1d]);
417
107k
    case_sz(1,   32,  8, [is_1d]);
418
223k
    case_sz(2,   64,  8, [is_1d]);
419
126k
    case_sz(3,  128,  8, [is_1d]);
420
154k
    case_sz(4,  256, 16, [is_1d]);
421
66.7k
    case_sz(5,  512, 16,        );
422
222k
    case_sz(6, 1024, 16,        );
423
1.12M
#undef case_sz
424
1.12M
    }
425
1.12M
    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.12M
    if (eob > 1) {
429
786k
        const int eob_bin = eob - 2;
430
786k
        uint16_t *const eob_hi_bit_cdf =
431
786k
            ts->cdf.coef.eob_hi_bit[t_dim->ctx][chroma][eob_bin];
432
786k
        const int eob_hi_bit = dav1d_msac_decode_bool_adapt(&ts->msac, eob_hi_bit_cdf);
433
786k
        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
786k
        eob = ((eob_hi_bit | 2) << eob_bin) | dav1d_msac_decode_bools(&ts->msac, eob_bin);
437
786k
        if (dbg)
438
0
            printf("Post-eob[%d]: r=%d\n", eob, ts->msac.rng);
439
786k
    }
440
1.12M
    assert(eob >= 0);
441
442
    // base tokens
443
1.12M
    uint16_t (*const eob_cdf)[4] = ts->cdf.coef.eob_base_tok[t_dim->ctx][chroma];
444
1.12M
    uint16_t (*const hi_cdf)[4] = ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
445
1.12M
    unsigned rc, dc_tok;
446
447
1.12M
    if (eob) {
448
834k
        uint16_t (*const lo_cdf)[4] = ts->cdf.coef.base_tok[t_dim->ctx][chroma];
449
834k
        uint8_t *const levels = t->scratch.levels; // bits 0-5: tok, 6-7: lo_tok
450
451
        /* eob */
452
834k
        unsigned ctx = 1 + (eob > 2 << tx2dszctx) + (eob > 4 << tx2dszctx);
453
834k
        int eob_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[ctx], 2);
454
834k
        int tok = eob_tok + 1;
455
834k
        int level_tok = tok * 0x41;
456
834k
        unsigned mag;
457
458
834k
#define DECODE_COEFS_CLASS(tx_class) \
459
834k
        unsigned x, y; \
460
834k
        uint8_t *level; \
461
834k
        if (tx_class == TX_CLASS_2D) \
462
834k
            rc = scan[eob], x = rc >> shift, y = rc & mask; \
463
834k
        else if (tx_class == TX_CLASS_H) \
464
            /* Transposing reduces the stride and padding requirements */ \
465
74.6k
            x = eob & mask, y = eob >> shift, rc = eob; \
466
74.6k
        else /* tx_class == TX_CLASS_V */ \
467
74.6k
            x = eob & mask, y = eob >> shift, rc = (x << shift2) | y; \
468
834k
        if (dbg) \
469
834k
            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
834k
        if (eob_tok == 2) { \
472
12.6k
            ctx = (tx_class == TX_CLASS_2D ? (x | y) > 1 : y != 0) ? 14 : 7; \
473
12.6k
            tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
474
12.6k
            level_tok = tok + (3 << 6); \
475
12.6k
            if (dbg) \
476
12.6k
                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
12.6k
        } \
480
834k
        cf[rc] = tok << 11; \
481
834k
        if (tx_class == TX_CLASS_2D) \
482
834k
            level = levels + rc; \
483
834k
        else \
484
834k
            level = levels + x * stride + y; \
485
834k
        *level = (uint8_t) level_tok; \
486
28.9M
        for (int i = eob - 1; i > 0; i--) { /* ac */ \
487
28.0M
            unsigned rc_i; \
488
28.0M
            if (tx_class == TX_CLASS_2D) \
489
28.0M
                rc_i = scan[i], x = rc_i >> shift, y = rc_i & mask; \
490
28.0M
            else if (tx_class == TX_CLASS_H) \
491
1.52M
                x = i & mask, y = i >> shift, rc_i = i; \
492
1.52M
            else /* tx_class == TX_CLASS_V */ \
493
1.52M
                x = i & mask, y = i >> shift, rc_i = (x << shift2) | y; \
494
28.0M
            assert(x < 32 && y < 32); \
495
28.0M
            if (tx_class == TX_CLASS_2D) \
496
28.0M
                level = levels + rc_i; \
497
28.0M
            else \
498
28.0M
                level = levels + x * stride + y; \
499
28.0M
            ctx = get_lo_ctx(level, tx_class, &mag, lo_ctx_offsets, x, y, stride); \
500
28.0M
            if (tx_class == TX_CLASS_2D) \
501
28.0M
                y |= x; \
502
28.0M
            tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
503
28.0M
            if (dbg) \
504
28.0M
                printf("Post-lo_tok[%d][%d][%d][%d=%d=%d]: r=%d\n", \
505
0
                       t_dim->ctx, chroma, ctx, i, rc_i, tok, ts->msac.rng); \
506
28.0M
            if (tok == 3) { \
507
1.53M
                mag &= 63; \
508
1.53M
                ctx = (y > (tx_class == TX_CLASS_2D) ? 14 : 7) + \
509
1.53M
                      (mag > 12 ? 6 : (mag + 1) >> 1); \
510
1.53M
                tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
511
1.53M
                if (dbg) \
512
1.53M
                    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.53M
                *level = (uint8_t) (tok + (3 << 6)); \
516
1.53M
                cf[rc_i] = (tok << 11) | rc; \
517
1.53M
                rc = rc_i; \
518
26.5M
            } else { \
519
                /* 0x1 for tok, 0x7ff as bitmask for rc, 0x41 for level_tok */ \
520
26.5M
                tok *= 0x17ff41; \
521
26.5M
                *level = (uint8_t) tok; \
522
                /* tok ? (tok << 11) | rc : 0 */ \
523
26.5M
                tok = (tok >> 9) & (rc + ~0x7ffu); \
524
26.5M
                if (tok) rc = rc_i; \
525
26.5M
                cf[rc_i] = tok; \
526
26.5M
            } \
527
28.0M
        } \
528
        /* dc */ \
529
834k
        ctx = (tx_class == TX_CLASS_2D) ? 0 : \
530
834k
            get_lo_ctx(levels, tx_class, &mag, lo_ctx_offsets, 0, 0, stride); \
531
834k
        dc_tok = dav1d_msac_decode_symbol_adapt4(&ts->msac, lo_cdf[ctx], 3); \
532
834k
        if (dbg) \
533
834k
            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
834k
        if (dc_tok == 3) { \
536
280k
            if (tx_class == TX_CLASS_2D) \
537
280k
                mag = levels[0 * stride + 1] + levels[1 * stride + 0] + \
538
274k
                      levels[1 * stride + 1]; \
539
280k
            mag &= 63; \
540
280k
            ctx = mag > 12 ? 6 : (mag + 1) >> 1; \
541
280k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[ctx]); \
542
280k
            if (dbg) \
543
280k
                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
280k
        } \
546
834k
        break
547
548
834k
        const uint16_t *scan;
549
834k
        switch (tx_class) {
550
759k
        case TX_CLASS_2D: {
551
759k
            const unsigned nonsquare_tx = tx >= RTX_4X8;
552
759k
            const uint8_t (*const lo_ctx_offsets)[5] =
553
759k
                dav1d_lo_ctx_offsets[nonsquare_tx + (tx & nonsquare_tx)];
554
759k
            scan = dav1d_scans[tx];
555
759k
            const ptrdiff_t stride = 4 << slh;
556
759k
            const unsigned shift = slh + 2, shift2 = 0;
557
759k
            const unsigned mask = (4 << slh) - 1;
558
759k
            memset(levels, 0, stride * ((4 << slw) + 2));
559
759k
            DECODE_COEFS_CLASS(TX_CLASS_2D);
560
759k
        }
561
48.7k
        case TX_CLASS_H: {
562
48.7k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
563
48.7k
            const ptrdiff_t stride = 16;
564
48.7k
            const unsigned shift = slh + 2, shift2 = 0;
565
48.7k
            const unsigned mask = (4 << slh) - 1;
566
48.7k
            memset(levels, 0, stride * ((4 << slh) + 2));
567
48.7k
            DECODE_COEFS_CLASS(TX_CLASS_H);
568
48.7k
        }
569
25.8k
        case TX_CLASS_V: {
570
25.8k
            const uint8_t (*const lo_ctx_offsets)[5] = NULL;
571
25.8k
            const ptrdiff_t stride = 16;
572
25.8k
            const unsigned shift = slw + 2, shift2 = slh + 2;
573
25.8k
            const unsigned mask = (4 << slw) - 1;
574
25.8k
            memset(levels, 0, stride * ((4 << slw) + 2));
575
25.8k
            DECODE_COEFS_CLASS(TX_CLASS_V);
576
25.8k
        }
577
0
#undef DECODE_COEFS_CLASS
578
0
        default: assert(0);
579
834k
        }
580
834k
    } else { // dc-only
581
289k
        int tok_br = dav1d_msac_decode_symbol_adapt4(&ts->msac, eob_cdf[0], 2);
582
289k
        dc_tok = 1 + tok_br;
583
289k
        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
289k
        if (tok_br == 2) {
587
22.3k
            dc_tok = dav1d_msac_decode_hi_tok(&ts->msac, hi_cdf[0]);
588
22.3k
            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
22.3k
        }
592
289k
        rc = 0;
593
289k
    }
594
595
    // residual and sign
596
1.12M
    const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
597
1.12M
    const uint8_t *const qm_tbl = *txtp < IDTX ? f->qm[tx][plane] : NULL;
598
1.12M
    const int dq_shift = imax(0, t_dim->ctx - 2);
599
1.12M
    const int cf_max = ~(~127U << (BITDEPTH == 8 ? 8 : f->cur.p.bpc));
600
1.12M
    unsigned cul_level, dc_sign_level;
601
602
1.12M
    if (!dc_tok) {
603
233k
        cul_level = 0;
604
233k
        dc_sign_level = 1 << 6;
605
233k
        if (qm_tbl) goto ac_qm;
606
130k
        goto ac_noqm;
607
233k
    }
608
609
890k
    const int dc_sign_ctx = get_dc_sign_ctx(tx, a, l);
610
890k
    uint16_t *const dc_sign_cdf = ts->cdf.coef.dc_sign[chroma][dc_sign_ctx];
611
890k
    const int dc_sign = dav1d_msac_decode_bool_adapt(&ts->msac, dc_sign_cdf);
612
890k
    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
890k
    int dc_dq = dq_tbl[0];
617
890k
    dc_sign_level = (dc_sign - 1) & (2 << 6);
618
619
890k
    if (qm_tbl) {
620
436k
        dc_dq = (dc_dq * qm_tbl[0] + 16) >> 5;
621
622
436k
        if (dc_tok == 15) {
623
10.5k
            dc_tok = read_golomb(&ts->msac) + 15;
624
10.5k
            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
10.5k
            dc_tok &= 0xfffff;
629
10.5k
            dc_dq = (dc_dq * dc_tok) & 0xffffff;
630
426k
        } else {
631
426k
            dc_dq *= dc_tok;
632
426k
            assert(dc_dq <= 0xffffff);
633
426k
        }
634
436k
        cul_level = dc_tok;
635
436k
        dc_dq >>= dq_shift;
636
436k
        dc_dq = umin(dc_dq, cf_max + dc_sign);
637
436k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
638
639
669k
        if (rc) ac_qm: {
640
669k
            const unsigned ac_dq = dq_tbl[1];
641
4.35M
            do {
642
4.35M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
643
4.35M
                if (dbg)
644
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
645
4.35M
                const unsigned rc_tok = cf[rc];
646
4.35M
                unsigned tok, dq = (ac_dq * qm_tbl[rc] + 16) >> 5;
647
4.35M
                int dq_sat;
648
649
4.35M
                if (rc_tok >= (15 << 11)) {
650
69.5k
                    tok = read_golomb(&ts->msac) + 15;
651
69.5k
                    if (dbg)
652
0
                        printf("Post-residual[%d=%d->%d]: r=%d\n",
653
0
                               rc, tok - 15, tok, ts->msac.rng);
654
655
69.5k
                    tok &= 0xfffff;
656
69.5k
                    dq = (dq * tok) & 0xffffff;
657
4.28M
                } else {
658
4.28M
                    tok = rc_tok >> 11;
659
4.28M
                    dq *= tok;
660
4.28M
                    assert(dq <= 0xffffff);
661
4.28M
                }
662
4.35M
                cul_level += tok;
663
4.35M
                dq >>= dq_shift;
664
4.35M
                dq_sat = umin(dq, cf_max + sign);
665
4.35M
                cf[rc] = (coef) (sign ? -dq_sat : dq_sat);
666
667
4.35M
                rc = rc_tok & 0x3ff;
668
4.35M
            } while (rc);
669
669k
        }
670
453k
    } else {
671
        // non-qmatrix is the common case and allows for additional optimizations
672
453k
        if (dc_tok == 15) {
673
13.2k
            dc_tok = read_golomb(&ts->msac) + 15;
674
13.2k
            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
13.2k
            dc_tok &= 0xfffff;
679
13.2k
            dc_dq = ((dc_dq * dc_tok) & 0xffffff) >> dq_shift;
680
13.2k
            dc_dq = umin(dc_dq, cf_max + dc_sign);
681
439k
        } else {
682
439k
            dc_dq = ((dc_dq * dc_tok) >> dq_shift);
683
439k
            assert(dc_dq <= cf_max);
684
439k
        }
685
453k
        cul_level = dc_tok;
686
453k
        cf[0] = (coef) (dc_sign ? -dc_dq : dc_dq);
687
688
767k
        if (rc) ac_noqm: {
689
767k
            const unsigned ac_dq = dq_tbl[1];
690
3.88M
            do {
691
3.88M
                const int sign = dav1d_msac_decode_bool_equi(&ts->msac);
692
3.88M
                if (dbg)
693
0
                    printf("Post-sign[%d=%d]: r=%d\n", rc, sign, ts->msac.rng);
694
3.88M
                const unsigned rc_tok = cf[rc];
695
3.88M
                unsigned tok;
696
3.88M
                int dq;
697
698
                // residual
699
3.88M
                if (rc_tok >= (15 << 11)) {
700
204k
                    tok = read_golomb(&ts->msac) + 15;
701
204k
                    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
204k
                    tok &= 0xfffff;
707
708
                    // dequant, see 7.12.3
709
204k
                    dq = ((ac_dq * tok) & 0xffffff) >> dq_shift;
710
204k
                    dq = umin(dq, cf_max + sign);
711
3.67M
                } else {
712
                    // cannot exceed cf_max, so we can avoid the clipping
713
3.67M
                    tok = rc_tok >> 11;
714
3.67M
                    dq = ((ac_dq * tok) >> dq_shift);
715
3.67M
                    assert(dq <= cf_max);
716
3.67M
                }
717
3.88M
                cul_level += tok;
718
3.88M
                cf[rc] = (coef) (sign ? -dq : dq);
719
720
3.88M
                rc = rc_tok & 0x3ff; // next non-zero rc, zero if eob
721
3.88M
            } while (rc);
722
767k
        }
723
453k
    }
724
725
    // context
726
1.12M
    *res_ctx = umin(cul_level, 63) | dc_sign_level;
727
728
1.12M
    return eob;
729
890k
}
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
461k
{
737
461k
    const Dav1dFrameContext *const f = t->f;
738
461k
    Dav1dTileState *const ts = t->ts;
739
461k
    const Dav1dDSPContext *const dsp = f->dsp;
740
461k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
741
461k
    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
461k
    if (depth < 2 && tx_split[depth] &&
746
48.7k
        tx_split[depth] & (1 << (y_off * 4 + x_off)))
747
36.8k
    {
748
36.8k
        const enum RectTxfmSize sub = t_dim->sub;
749
36.8k
        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
750
36.8k
        const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
751
752
36.8k
        read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
753
36.8k
                       x_off * 2 + 0, y_off * 2 + 0, dst);
754
36.8k
        t->bx += txsw;
755
36.8k
        if (txw >= txh && t->bx < f->bw)
756
28.9k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
757
28.9k
                           y_off * 2 + 0, dst ? &dst[4 * txsw] : NULL);
758
36.8k
        t->bx -= txsw;
759
36.8k
        t->by += txsh;
760
36.8k
        if (txh >= txw && t->by < f->bh) {
761
26.8k
            if (dst)
762
5.18k
                dst += 4 * txsh * PXSTRIDE(f->cur.stride[0]);
763
26.8k
            read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
764
26.8k
                           x_off * 2 + 0, y_off * 2 + 1, dst);
765
26.8k
            t->bx += txsw;
766
26.8k
            if (txw >= txh && t->bx < f->bw)
767
19.2k
                read_coef_tree(t, bs, b, sub, depth + 1, tx_split, x_off * 2 + 1,
768
19.2k
                               y_off * 2 + 1, dst ? &dst[4 * txsw] : NULL);
769
26.8k
            t->bx -= txsw;
770
26.8k
        }
771
36.8k
        t->by -= txsh;
772
424k
    } else {
773
424k
        const int bx4 = t->bx & 31, by4 = t->by & 31;
774
424k
        enum TxfmType txtp;
775
424k
        uint8_t cf_ctx;
776
424k
        int eob;
777
424k
        coef *cf;
778
779
424k
        if (t->frame_thread.pass) {
780
424k
            const int p = t->frame_thread.pass & 1;
781
424k
            assert(ts->frame_thread[p].cf);
782
424k
            cf = ts->frame_thread[p].cf;
783
424k
            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
424k
        if (t->frame_thread.pass != 2) {
788
313k
            eob = decode_coefs(t, &t->a->lcoef[bx4], &t->l.lcoef[by4],
789
313k
                               ytx, bs, b, 0, 0, cf, &txtp, &cf_ctx);
790
313k
            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
313k
            dav1d_memset_likely_pow2(&t->a->lcoef[bx4], cf_ctx, imin(txw, f->bw - t->bx));
794
313k
            dav1d_memset_likely_pow2(&t->l.lcoef[by4], cf_ctx, imin(txh, f->bh - t->by));
795
313k
#define set_ctx(rep_macro) \
796
1.36M
            for (int y = 0; y < txh; y++) { \
797
1.05M
                rep_macro(txtp_map, 0, txtp); \
798
1.05M
                txtp_map += 32; \
799
1.05M
            }
800
313k
            uint8_t *txtp_map = &t->scratch.txtp_map[by4 * 32 + bx4];
801
313k
            case_set_upto16(t_dim->lw);
802
313k
#undef set_ctx
803
313k
            if (t->frame_thread.pass == 1)
804
313k
                *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
805
313k
        } else {
806
111k
            const int cbi = *ts->frame_thread[0].cbi++;
807
111k
            eob  = cbi >> 5;
808
111k
            txtp = cbi & 0x1f;
809
111k
        }
810
424k
        if (!(t->frame_thread.pass & 1)) {
811
111k
            assert(dst);
812
111k
            if (eob >= 0) {
813
74.3k
                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
74.3k
                dsp->itx.itxfm_add[ytx][txtp](dst, f->cur.stride[0], cf, eob
816
74.3k
                                              HIGHBD_CALL_SUFFIX);
817
74.3k
                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
74.3k
            }
820
111k
        }
821
424k
    }
822
461k
}
823
824
void bytefn(dav1d_read_coef_blocks)(Dav1dTaskContext *const t,
825
                                    const enum BlockSize bs, const Av1Block *const b)
826
1.32M
{
827
1.32M
    const Dav1dFrameContext *const f = t->f;
828
1.32M
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
1.32M
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
1.32M
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
1.32M
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
1.32M
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
1.32M
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
1.32M
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
1.32M
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
1.00M
                           (bw4 > ss_hor || t->bx & 1) &&
837
966k
                           (bh4 > ss_ver || t->by & 1);
838
839
1.32M
    if (b->skip) {
840
742k
        BlockContext *const a = t->a;
841
742k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
742k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
742k
        if (has_chroma) {
844
503k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
503k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
503k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
503k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
503k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
503k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
503k
        }
851
742k
        return;
852
742k
    }
853
854
579k
    Dav1dTileState *const ts = t->ts;
855
579k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
579k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
579k
    assert(t->frame_thread.pass == 1);
858
579k
    assert(!b->skip);
859
579k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
579k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
579k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
1.17M
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
600k
        const int sub_h4 = imin(h4, 16 + init_y);
865
1.23M
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
632k
            const int sub_w4 = imin(w4, init_x + 16);
867
632k
            int y_off = !!init_y, y, x;
868
1.36M
            for (y = init_y, t->by += init_y; y < sub_h4;
869
732k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
732k
            {
871
732k
                int x_off = !!init_x;
872
1.70M
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
968k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
968k
                {
875
968k
                    if (!b->intra) {
876
252k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
252k
                                       x_off, y_off, NULL);
878
716k
                    } else {
879
716k
                        uint8_t cf_ctx = 0x40;
880
716k
                        enum TxfmType txtp;
881
716k
                        const int eob =
882
716k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
716k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
716k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
716k
                        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
716k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
716k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
716k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
716k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
716k
                    }
893
968k
                }
894
732k
                t->bx -= x;
895
732k
            }
896
632k
            t->by -= y;
897
898
632k
            if (!has_chroma) continue;
899
900
469k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
469k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
1.40M
            for (int pl = 0; pl < 2; pl++) {
903
1.98M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
1.05M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
1.05M
                {
906
2.35M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
1.30M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
1.30M
                    {
909
1.30M
                        uint8_t cf_ctx = 0x40;
910
1.30M
                        enum TxfmType txtp;
911
1.30M
                        if (!b->intra)
912
325k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
325k
                                                        bx4 + (x << ss_hor)];
914
1.30M
                        const int eob =
915
1.30M
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
1.30M
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
1.30M
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
1.30M
                                         &txtp, &cf_ctx);
919
1.30M
                        if (DEBUG_BLOCK_INFO)
920
0
                            printf("Post-uv-cf-blk[pl=%d,tx=%d,"
921
0
                                   "txtp=%d,eob=%d]: r=%d\n",
922
0
                                   pl, b->uvtx, txtp, eob, ts->msac.rng);
923
1.30M
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
1.30M
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
1.30M
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
1.30M
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
1.30M
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
1.30M
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
1.30M
                    }
930
1.05M
                    t->bx -= x << ss_hor;
931
1.05M
                }
932
938k
                t->by -= y << ss_ver;
933
938k
            }
934
469k
        }
935
600k
    }
936
579k
}
dav1d_read_coef_blocks_8bpc
Line
Count
Source
826
638k
{
827
638k
    const Dav1dFrameContext *const f = t->f;
828
638k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
638k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
638k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
638k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
638k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
638k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
638k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
638k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
473k
                           (bw4 > ss_hor || t->bx & 1) &&
837
451k
                           (bh4 > ss_ver || t->by & 1);
838
839
638k
    if (b->skip) {
840
359k
        BlockContext *const a = t->a;
841
359k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
359k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
359k
        if (has_chroma) {
844
236k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
236k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
236k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
236k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
236k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
236k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
236k
        }
851
359k
        return;
852
359k
    }
853
854
279k
    Dav1dTileState *const ts = t->ts;
855
279k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
279k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
279k
    assert(t->frame_thread.pass == 1);
858
279k
    assert(!b->skip);
859
279k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
279k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
279k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
570k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
290k
        const int sub_h4 = imin(h4, 16 + init_y);
865
597k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
307k
            const int sub_w4 = imin(w4, init_x + 16);
867
307k
            int y_off = !!init_y, y, x;
868
664k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
357k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
357k
            {
871
357k
                int x_off = !!init_x;
872
816k
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
459k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
459k
                {
875
459k
                    if (!b->intra) {
876
136k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
136k
                                       x_off, y_off, NULL);
878
323k
                    } else {
879
323k
                        uint8_t cf_ctx = 0x40;
880
323k
                        enum TxfmType txtp;
881
323k
                        const int eob =
882
323k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
323k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
323k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
323k
                        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
323k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
323k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
323k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
323k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
323k
                    }
893
459k
                }
894
357k
                t->bx -= x;
895
357k
            }
896
307k
            t->by -= y;
897
898
307k
            if (!has_chroma) continue;
899
900
217k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
217k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
651k
            for (int pl = 0; pl < 2; pl++) {
903
925k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
490k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
490k
                {
906
1.09M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
600k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
600k
                    {
909
600k
                        uint8_t cf_ctx = 0x40;
910
600k
                        enum TxfmType txtp;
911
600k
                        if (!b->intra)
912
169k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
169k
                                                        bx4 + (x << ss_hor)];
914
600k
                        const int eob =
915
600k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
600k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
600k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
600k
                                         &txtp, &cf_ctx);
919
600k
                        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
600k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
600k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
600k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
600k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
600k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
600k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
600k
                    }
930
490k
                    t->bx -= x << ss_hor;
931
490k
                }
932
434k
                t->by -= y << ss_ver;
933
434k
            }
934
217k
        }
935
290k
    }
936
279k
}
dav1d_read_coef_blocks_16bpc
Line
Count
Source
826
682k
{
827
682k
    const Dav1dFrameContext *const f = t->f;
828
682k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
829
682k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
830
682k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
831
682k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
832
682k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
833
682k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
834
682k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
835
682k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
836
531k
                           (bw4 > ss_hor || t->bx & 1) &&
837
514k
                           (bh4 > ss_ver || t->by & 1);
838
839
682k
    if (b->skip) {
840
383k
        BlockContext *const a = t->a;
841
383k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
842
383k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
843
383k
        if (has_chroma) {
844
266k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
845
266k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
846
266k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
847
266k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
848
266k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
849
266k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
850
266k
        }
851
383k
        return;
852
383k
    }
853
854
299k
    Dav1dTileState *const ts = t->ts;
855
299k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
856
299k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
857
299k
    assert(t->frame_thread.pass == 1);
858
299k
    assert(!b->skip);
859
299k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
860
299k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
861
299k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
862
863
609k
    for (int init_y = 0; init_y < h4; init_y += 16) {
864
309k
        const int sub_h4 = imin(h4, 16 + init_y);
865
635k
        for (int init_x = 0; init_x < w4; init_x += 16) {
866
325k
            const int sub_w4 = imin(w4, init_x + 16);
867
325k
            int y_off = !!init_y, y, x;
868
700k
            for (y = init_y, t->by += init_y; y < sub_h4;
869
375k
                 y += t_dim->h, t->by += t_dim->h, y_off++)
870
375k
            {
871
375k
                int x_off = !!init_x;
872
884k
                for (x = init_x, t->bx += init_x; x < sub_w4;
873
509k
                     x += t_dim->w, t->bx += t_dim->w, x_off++)
874
509k
                {
875
509k
                    if (!b->intra) {
876
115k
                        read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
877
115k
                                       x_off, y_off, NULL);
878
393k
                    } else {
879
393k
                        uint8_t cf_ctx = 0x40;
880
393k
                        enum TxfmType txtp;
881
393k
                        const int eob =
882
393k
                            decode_coefs(t, &t->a->lcoef[bx4 + x],
883
393k
                                         &t->l.lcoef[by4 + y], b->tx, bs, b, 1,
884
393k
                                         0, ts->frame_thread[1].cf, &txtp, &cf_ctx);
885
393k
                        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
393k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
889
393k
                        ts->frame_thread[1].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
890
393k
                        dav1d_memset_likely_pow2(&t->a->lcoef[bx4 + x], cf_ctx, imin(t_dim->w, f->bw - t->bx));
891
393k
                        dav1d_memset_likely_pow2(&t->l.lcoef[by4 + y], cf_ctx, imin(t_dim->h, f->bh - t->by));
892
393k
                    }
893
509k
                }
894
375k
                t->bx -= x;
895
375k
            }
896
325k
            t->by -= y;
897
898
325k
            if (!has_chroma) continue;
899
900
251k
            const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
901
251k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
902
755k
            for (int pl = 0; pl < 2; pl++) {
903
1.06M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
904
559k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
905
559k
                {
906
1.26M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
907
700k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
908
700k
                    {
909
700k
                        uint8_t cf_ctx = 0x40;
910
700k
                        enum TxfmType txtp;
911
700k
                        if (!b->intra)
912
156k
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
913
156k
                                                        bx4 + (x << ss_hor)];
914
700k
                        const int eob =
915
700k
                            decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
916
700k
                                         &t->l.ccoef[pl][cby4 + y], b->uvtx, bs,
917
700k
                                         b, b->intra, 1 + pl, ts->frame_thread[1].cf,
918
700k
                                         &txtp, &cf_ctx);
919
700k
                        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
700k
                        *ts->frame_thread[1].cbi++ = eob * (1 << 5) + txtp;
924
700k
                        ts->frame_thread[1].cf += uv_t_dim->w * uv_t_dim->h * 16;
925
700k
                        int ctw = imin(uv_t_dim->w, (f->bw - t->bx + ss_hor) >> ss_hor);
926
700k
                        int cth = imin(uv_t_dim->h, (f->bh - t->by + ss_ver) >> ss_ver);
927
700k
                        dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
928
700k
                        dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
929
700k
                    }
930
559k
                    t->bx -= x << ss_hor;
931
559k
                }
932
503k
                t->by -= y << ss_ver;
933
503k
            }
934
251k
        }
935
309k
    }
936
299k
}
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
433k
{
945
433k
    assert((dst8 != NULL) ^ (dst16 != NULL));
946
433k
    const Dav1dFrameContext *const f = t->f;
947
433k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
948
433k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
949
433k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
950
433k
    const int mvx = mv.x, mvy = mv.y;
951
433k
    const int mx = mvx & (15 >> !ss_hor), my = mvy & (15 >> !ss_ver);
952
433k
    ptrdiff_t ref_stride = refp->p.stride[!!pl];
953
433k
    const pixel *ref;
954
955
433k
    if (refp->p.p.w == f->cur.p.w && refp->p.p.h == f->cur.p.h) {
956
209k
        const int dx = bx * h_mul + (mvx >> (3 + ss_hor));
957
209k
        const int dy = by * v_mul + (mvy >> (3 + ss_ver));
958
209k
        int w, h;
959
960
209k
        if (refp->p.data[0] != f->cur.data[0]) { // i.e. not for intrabc
961
96.4k
            w = (f->cur.p.w + ss_hor) >> ss_hor;
962
96.4k
            h = (f->cur.p.h + ss_ver) >> ss_ver;
963
112k
        } else {
964
112k
            w = f->bw * 4 >> ss_hor;
965
112k
            h = f->bh * 4 >> ss_ver;
966
112k
        }
967
209k
        if (dx < !!mx * 3 || dy < !!my * 3 ||
968
179k
            dx + bw4 * h_mul + !!mx * 4 > w ||
969
146k
            dy + bh4 * v_mul + !!my * 4 > h)
970
70.1k
        {
971
70.1k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
972
70.1k
            f->dsp->mc.emu_edge(bw4 * h_mul + !!mx * 7, bh4 * v_mul + !!my * 7,
973
70.1k
                                w, h, dx - !!mx * 3, dy - !!my * 3,
974
70.1k
                                emu_edge_buf, 192 * sizeof(pixel),
975
70.1k
                                refp->p.data[pl], ref_stride);
976
70.1k
            ref = &emu_edge_buf[192 * !!my * 3 + !!mx * 3];
977
70.1k
            ref_stride = 192 * sizeof(pixel);
978
139k
        } else {
979
139k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
980
139k
        }
981
982
209k
        if (dst8 != NULL) {
983
184k
            f->dsp->mc.mc[filter_2d](dst8, dst_stride, ref, ref_stride, bw4 * h_mul,
984
184k
                                     bh4 * v_mul, mx << !ss_hor, my << !ss_ver
985
184k
                                     HIGHBD_CALL_SUFFIX);
986
184k
        } else {
987
24.9k
            f->dsp->mc.mct[filter_2d](dst16, ref, ref_stride, bw4 * h_mul,
988
24.9k
                                      bh4 * v_mul, mx << !ss_hor, my << !ss_ver
989
24.9k
                                      HIGHBD_CALL_SUFFIX);
990
24.9k
        }
991
224k
    } else {
992
224k
        assert(refp != &f->sr_cur);
993
994
224k
        const int orig_pos_y = (by * v_mul << 4) + mvy * (1 << !ss_ver);
995
224k
        const int orig_pos_x = (bx * h_mul << 4) + mvx * (1 << !ss_hor);
996
449k
#define scale_mv(res, val, scale) do { \
997
449k
            const int64_t tmp = (int64_t)(val) * scale + (scale - 0x4000) * 8; \
998
449k
            res = apply_sign64((int) ((llabs(tmp) + 128) >> 8), tmp) + 32;     \
999
449k
        } while (0)
1000
224k
        int pos_y, pos_x;
1001
224k
        scale_mv(pos_x, orig_pos_x, f->svc[refidx][0].scale);
1002
224k
        scale_mv(pos_y, orig_pos_y, f->svc[refidx][1].scale);
1003
224k
#undef scale_mv
1004
224k
        const int left = pos_x >> 10;
1005
224k
        const int top = pos_y >> 10;
1006
224k
        const int right =
1007
224k
            ((pos_x + (bw4 * h_mul - 1) * f->svc[refidx][0].step) >> 10) + 1;
1008
224k
        const int bottom =
1009
224k
            ((pos_y + (bh4 * v_mul - 1) * f->svc[refidx][1].step) >> 10) + 1;
1010
1011
224k
        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
224k
        const int w = (refp->p.p.w + ss_hor) >> ss_hor;
1018
224k
        const int h = (refp->p.p.h + ss_ver) >> ss_ver;
1019
224k
        if (left < 3 || top < 3 || right + 4 > w || bottom + 4 > h) {
1020
100k
            pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1021
100k
            f->dsp->mc.emu_edge(right - left + 7, bottom - top + 7,
1022
100k
                                w, h, left - 3, top - 3,
1023
100k
                                emu_edge_buf, 320 * sizeof(pixel),
1024
100k
                                refp->p.data[pl], ref_stride);
1025
100k
            ref = &emu_edge_buf[320 * 3 + 3];
1026
100k
            ref_stride = 320 * sizeof(pixel);
1027
100k
            if (DEBUG_BLOCK_INFO) printf("Emu\n");
1028
124k
        } else {
1029
124k
            ref = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * top + left;
1030
124k
        }
1031
1032
224k
        if (dst8 != NULL) {
1033
210k
            f->dsp->mc.mc_scaled[filter_2d](dst8, dst_stride, ref, ref_stride,
1034
210k
                                            bw4 * h_mul, bh4 * v_mul,
1035
210k
                                            pos_x & 0x3ff, pos_y & 0x3ff,
1036
210k
                                            f->svc[refidx][0].step,
1037
210k
                                            f->svc[refidx][1].step
1038
210k
                                            HIGHBD_CALL_SUFFIX);
1039
210k
        } else {
1040
14.5k
            f->dsp->mc.mct_scaled[filter_2d](dst16, ref, ref_stride,
1041
14.5k
                                             bw4 * h_mul, bh4 * v_mul,
1042
14.5k
                                             pos_x & 0x3ff, pos_y & 0x3ff,
1043
14.5k
                                             f->svc[refidx][0].step,
1044
14.5k
                                             f->svc[refidx][1].step
1045
14.5k
                                             HIGHBD_CALL_SUFFIX);
1046
14.5k
        }
1047
224k
    }
1048
1049
433k
    return 0;
1050
433k
}
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
48.5k
{
1057
48.5k
    assert(!(t->bx & 1) && !(t->by & 1));
1058
48.5k
    const Dav1dFrameContext *const f = t->f;
1059
48.5k
    /*const*/ refmvs_block **r = &t->rt.r[(t->by & 31) + 5];
1060
48.5k
    pixel *const lap = bitfn(t->scratch.lap);
1061
48.5k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1062
48.5k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1063
48.5k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1064
48.5k
    int res;
1065
1066
48.5k
    if (t->by > t->ts->tiling.row_start &&
1067
45.2k
        (!pl || b_dim[0] * h_mul + b_dim[1] * v_mul >= 16))
1068
26.6k
    {
1069
56.4k
        for (int i = 0, x = 0; x < w4 && i < imin(b_dim[2], 4); ) {
1070
            // only odd blocks are considered for overlap handling, hence +1
1071
29.7k
            const refmvs_block *const a_r = &r[-1][t->bx + x + 1];
1072
29.7k
            const uint8_t *const a_b_dim = dav1d_block_dimensions[a_r->bs];
1073
29.7k
            const int step4 = iclip(a_b_dim[0], 2, 16);
1074
1075
29.7k
            if (a_r->ref.ref[0] > 0) {
1076
29.2k
                const int ow4 = imin(step4, b_dim[0]);
1077
29.2k
                const int oh4 = imin(b_dim[1], 16) >> 1;
1078
29.2k
                res = mc(t, lap, NULL, ow4 * h_mul * sizeof(pixel), ow4, (oh4 * 3 + 3) >> 2,
1079
29.2k
                         t->bx + x, t->by, pl, a_r->mv.mv[0],
1080
29.2k
                         &f->refp[a_r->ref.ref[0] - 1], a_r->ref.ref[0] - 1,
1081
29.2k
                         dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
1082
29.2k
                if (res) return res;
1083
29.2k
                f->dsp->mc.blend_h(&dst[x * h_mul], dst_stride, lap,
1084
29.2k
                                   h_mul * ow4, v_mul * oh4);
1085
29.2k
                i++;
1086
29.2k
            }
1087
29.7k
            x += step4;
1088
29.7k
        }
1089
26.6k
    }
1090
1091
48.5k
    if (t->bx > t->ts->tiling.col_start)
1092
93.8k
        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
48.7k
            const refmvs_block *const l_r = &r[y + 1][t->bx - 1];
1095
48.7k
            const uint8_t *const l_b_dim = dav1d_block_dimensions[l_r->bs];
1096
48.7k
            const int step4 = iclip(l_b_dim[1], 2, 16);
1097
1098
48.7k
            if (l_r->ref.ref[0] > 0) {
1099
48.1k
                const int ow4 = imin(b_dim[0], 16) >> 1;
1100
48.1k
                const int oh4 = imin(step4, b_dim[1]);
1101
48.1k
                res = mc(t, lap, NULL, h_mul * ow4 * sizeof(pixel), ow4, oh4,
1102
48.1k
                         t->bx, t->by + y, pl, l_r->mv.mv[0],
1103
48.1k
                         &f->refp[l_r->ref.ref[0] - 1], l_r->ref.ref[0] - 1,
1104
48.1k
                         dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
1105
48.1k
                if (res) return res;
1106
48.1k
                f->dsp->mc.blend_v(&dst[y * v_mul * PXSTRIDE(dst_stride)],
1107
48.1k
                                   dst_stride, lap, h_mul * ow4, v_mul * oh4);
1108
48.1k
                i++;
1109
48.1k
            }
1110
48.7k
            y += step4;
1111
48.7k
        }
1112
48.5k
    return 0;
1113
48.5k
}
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
3.56k
{
1121
3.56k
    assert((dst8 != NULL) ^ (dst16 != NULL));
1122
3.56k
    const Dav1dFrameContext *const f = t->f;
1123
3.56k
    const Dav1dDSPContext *const dsp = f->dsp;
1124
3.56k
    const int ss_ver = !!pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1125
3.56k
    const int ss_hor = !!pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1126
3.56k
    const int h_mul = 4 >> ss_hor, v_mul = 4 >> ss_ver;
1127
3.56k
    assert(!((b_dim[0] * h_mul) & 7) && !((b_dim[1] * v_mul) & 7));
1128
3.56k
    const int32_t *const mat = wmp->matrix;
1129
3.56k
    const int width = (refp->p.p.w + ss_hor) >> ss_hor;
1130
3.56k
    const int height = (refp->p.p.h + ss_ver) >> ss_ver;
1131
1132
11.4k
    for (int y = 0; y < b_dim[1] * v_mul; y += 8) {
1133
7.86k
        const int src_y = t->by * 4 + ((y + 4) << ss_ver);
1134
7.86k
        const int64_t mat3_y = (int64_t) mat[3] * src_y + mat[0];
1135
7.86k
        const int64_t mat5_y = (int64_t) mat[5] * src_y + mat[1];
1136
31.7k
        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
23.8k
            const int src_x = t->bx * 4 + ((x + 4) << ss_hor);
1140
23.8k
            const int64_t mvx = ((int64_t) mat[2] * src_x + mat3_y) >> ss_hor;
1141
23.8k
            const int64_t mvy = ((int64_t) mat[4] * src_x + mat5_y) >> ss_ver;
1142
1143
23.8k
            const int dx = (int) (mvx >> 16) - 4;
1144
23.8k
            const int mx = (((int) mvx & 0xffff) - wmp->u.p.alpha * 4 -
1145
23.8k
                                                   wmp->u.p.beta  * 7) & ~0x3f;
1146
23.8k
            const int dy = (int) (mvy >> 16) - 4;
1147
23.8k
            const int my = (((int) mvy & 0xffff) - wmp->u.p.gamma * 4 -
1148
23.8k
                                                   wmp->u.p.delta * 4) & ~0x3f;
1149
1150
23.8k
            const pixel *ref_ptr;
1151
23.8k
            ptrdiff_t ref_stride = refp->p.stride[!!pl];
1152
1153
23.8k
            if (dx < 3 || dx + 8 + 4 > width || dy < 3 || dy + 8 + 4 > height) {
1154
17.1k
                pixel *const emu_edge_buf = bitfn(t->scratch.emu_edge);
1155
17.1k
                f->dsp->mc.emu_edge(15, 15, width, height, dx - 3, dy - 3,
1156
17.1k
                                    emu_edge_buf, 32 * sizeof(pixel),
1157
17.1k
                                    refp->p.data[pl], ref_stride);
1158
17.1k
                ref_ptr = &emu_edge_buf[32 * 3 + 3];
1159
17.1k
                ref_stride = 32 * sizeof(pixel);
1160
17.1k
            } else {
1161
6.77k
                ref_ptr = ((pixel *) refp->p.data[pl]) + PXSTRIDE(ref_stride) * dy + dx;
1162
6.77k
            }
1163
23.8k
            if (dst16 != NULL)
1164
2.98k
                dsp->mc.warp8x8t(&dst16[x], dstride, ref_ptr, ref_stride,
1165
2.98k
                                 wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1166
20.9k
            else
1167
20.9k
                dsp->mc.warp8x8(&dst8[x], dstride, ref_ptr, ref_stride,
1168
20.9k
                                wmp->u.abcd, mx, my HIGHBD_CALL_SUFFIX);
1169
23.8k
        }
1170
7.86k
        if (dst8) dst8  += 8 * PXSTRIDE(dstride);
1171
957
        else      dst16 += 8 * dstride;
1172
7.86k
    }
1173
3.56k
    return 0;
1174
3.56k
}
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
585k
{
1180
585k
    Dav1dTileState *const ts = t->ts;
1181
585k
    const Dav1dFrameContext *const f = t->f;
1182
585k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
585k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
585k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
585k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
585k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
585k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
585k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
585k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
585k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
585k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
459k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
444k
                           (bh4 > ss_ver || t->by & 1);
1194
585k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
585k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
585k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
585k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
585k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
1.19M
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
613k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
613k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
1.26M
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
651k
            if (b->pal_sz[0]) {
1208
3.50k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
3.50k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
3.50k
                const uint8_t *pal_idx;
1211
3.50k
                if (t->frame_thread.pass) {
1212
3.50k
                    const int p = t->frame_thread.pass & 1;
1213
3.50k
                    assert(ts->frame_thread[p].pal_idx);
1214
3.50k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
3.50k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
3.50k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
3.50k
                const pixel *const pal = t->frame_thread.pass ?
1220
3.50k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
3.50k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
3.50k
                    bytefn(t->scratch.pal)[0];
1223
3.50k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
3.50k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
3.50k
                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.50k
            }
1229
1230
651k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
651k
                                     sm_flag(&t->l, by4) |
1232
651k
                                     intra_edge_filter_flag);
1233
651k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
613k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
651k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
613k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
651k
            int y, x;
1238
651k
            const int sub_w4 = imin(w4, init_x + 16);
1239
1.49M
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
847k
                 y += t_dim->h, t->by += t_dim->h)
1241
848k
            {
1242
848k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
848k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
848k
                                    t->bx + init_x);
1245
2.12M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
1.27M
                     x += t_dim->w, t->bx += t_dim->w)
1247
1.27M
                {
1248
1.27M
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
1.26M
                    int angle = b->y_angle;
1251
1.26M
                    const enum EdgeFlags edge_flags =
1252
1.26M
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
908k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
1.26M
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
731k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
1.26M
                    const pixel *top_sb_edge = NULL;
1257
1.26M
                    if (!(t->by & (f->sb_step - 1))) {
1258
242k
                        top_sb_edge = f->ipred_edge[0];
1259
242k
                        const int sby = t->by >> f->sb_shift;
1260
242k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
242k
                    }
1262
1.26M
                    const enum IntraPredMode m =
1263
1.26M
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
1.26M
                                                          t->bx > ts->tiling.col_start,
1265
1.26M
                                                          t->by,
1266
1.26M
                                                          t->by > ts->tiling.row_start,
1267
1.26M
                                                          ts->tiling.col_end,
1268
1.26M
                                                          ts->tiling.row_end,
1269
1.26M
                                                          edge_flags, dst,
1270
1.26M
                                                          f->cur.stride[0], top_sb_edge,
1271
1.26M
                                                          b->y_mode, &angle,
1272
1.26M
                                                          t_dim->w, t_dim->h,
1273
1.26M
                                                          f->seq_hdr->intra_edge_filter,
1274
1.26M
                                                          edge HIGHBD_CALL_SUFFIX);
1275
1.26M
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
1.26M
                                             t_dim->w * 4, t_dim->h * 4,
1277
1.26M
                                             angle | intra_flags,
1278
1.26M
                                             4 * f->bw - 4 * t->bx,
1279
1.26M
                                             4 * f->bh - 4 * t->by
1280
1.26M
                                             HIGHBD_CALL_SUFFIX);
1281
1282
1.26M
                    if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1283
0
                        hex_dump(edge - t_dim->h * 4, t_dim->h * 4,
1284
0
                                 t_dim->h * 4, 2, "l");
1285
0
                        hex_dump(edge, 0, 1, 1, "tl");
1286
0
                        hex_dump(edge + 1, t_dim->w * 4,
1287
0
                                 t_dim->w * 4, 2, "t");
1288
0
                        hex_dump(dst, f->cur.stride[0],
1289
0
                                 t_dim->w * 4, t_dim->h * 4, "y-intra-pred");
1290
0
                    }
1291
1292
1.27M
                skip_y_pred: {}
1293
1.27M
                    if (!b->skip) {
1294
400k
                        coef *cf;
1295
400k
                        int eob;
1296
400k
                        enum TxfmType txtp;
1297
400k
                        if (t->frame_thread.pass) {
1298
400k
                            const int p = t->frame_thread.pass & 1;
1299
400k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
400k
                            cf = ts->frame_thread[p].cf;
1301
400k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
400k
                            eob  = cbi >> 5;
1303
400k
                            txtp = cbi & 0x1f;
1304
400k
                        } 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
400k
                        if (eob >= 0) {
1317
261k
                            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
261k
                            dsp->itx.itxfm_add[b->tx]
1321
261k
                                              [txtp](dst,
1322
261k
                                                     f->cur.stride[0],
1323
261k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
261k
                            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
261k
                        }
1328
872k
                    } else if (!t->frame_thread.pass) {
1329
0
                        dav1d_memset_pow2[t_dim->lw](&t->a->lcoef[bx4 + x], 0x40);
1330
0
                        dav1d_memset_pow2[t_dim->lh](&t->l.lcoef[by4 + y], 0x40);
1331
0
                    }
1332
1.27M
                    dst += 4 * t_dim->w;
1333
1.27M
                }
1334
847k
                t->bx -= x;
1335
847k
            }
1336
651k
            t->by -= y;
1337
1338
651k
            if (!has_chroma) continue;
1339
1340
486k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
486k
            if (b->uv_mode == CFL_PRED) {
1343
78.5k
                assert(!init_x && !init_y);
1344
1345
78.5k
                int16_t *const ac = t->scratch.ac;
1346
78.5k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
78.5k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
78.5k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
78.5k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
78.5k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
78.5k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
78.5k
                const int furthest_r =
1354
78.5k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
78.5k
                const int furthest_b =
1356
78.5k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
78.5k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
78.5k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
78.5k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
78.5k
                                                         cbw4 * 4, cbh4 * 4);
1361
235k
                for (int pl = 0; pl < 2; pl++) {
1362
157k
                    if (!b->cfl_alpha[pl]) continue;
1363
122k
                    int angle = 0;
1364
122k
                    const pixel *top_sb_edge = NULL;
1365
122k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
25.5k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
25.5k
                        const int sby = t->by >> f->sb_shift;
1368
25.5k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
25.5k
                    }
1370
122k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
122k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
122k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
122k
                    const enum IntraPredMode m =
1374
122k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
122k
                                                          ypos, ypos > ystart,
1376
122k
                                                          ts->tiling.col_end >> ss_hor,
1377
122k
                                                          ts->tiling.row_end >> ss_ver,
1378
122k
                                                          0, uv_dst[pl], stride,
1379
122k
                                                          top_sb_edge, DC_PRED, &angle,
1380
122k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
122k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
122k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
122k
                                           uv_t_dim->w * 4,
1384
122k
                                           uv_t_dim->h * 4,
1385
122k
                                           ac, b->cfl_alpha[pl]
1386
122k
                                           HIGHBD_CALL_SUFFIX);
1387
122k
                }
1388
78.5k
                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
407k
            } else if (b->pal_sz[1]) {
1394
892
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
892
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
892
                const pixel (*pal)[8];
1397
892
                const uint8_t *pal_idx;
1398
892
                if (t->frame_thread.pass) {
1399
892
                    const int p = t->frame_thread.pass & 1;
1400
892
                    assert(ts->frame_thread[p].pal_idx);
1401
892
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
892
                                              ((t->bx >> 1) + (t->by & 1))];
1403
892
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
892
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
892
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
892
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
892
                                       f->cur.stride[1], pal[1],
1412
892
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
892
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
892
                                       f->cur.stride[1], pal[2],
1415
892
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
892
                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
892
            }
1425
1426
486k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
486k
                                 sm_uv_flag(&t->l, cby4);
1428
486k
            const int uv_sb_has_tr =
1429
486k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
454k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
486k
            const int uv_sb_has_bl =
1432
486k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
454k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
486k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
1.45M
            for (int pl = 0; pl < 2; pl++) {
1436
2.04M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
1.07M
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
1.07M
                {
1439
1.07M
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
1.07M
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
1.07M
                                        ((t->bx + init_x) >> ss_hor));
1442
2.32M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
1.24M
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
1.25M
                    {
1445
1.25M
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
1.12M
                            b->pal_sz[1])
1447
124k
                        {
1448
124k
                            goto skip_uv_pred;
1449
124k
                        }
1450
1451
1.12M
                        int angle = b->uv_angle;
1452
                        // this probably looks weird because we're using
1453
                        // luma flags in a chroma loop, but that's because
1454
                        // prepare_intra_edges() expects luma flags as input
1455
1.12M
                        const enum EdgeFlags edge_flags =
1456
1.12M
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
420k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
809k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
1.12M
                            ((x > (init_x >> ss_hor) ||
1460
948k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
590k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
1.12M
                        const pixel *top_sb_edge = NULL;
1463
1.12M
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
332k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
332k
                            const int sby = t->by >> f->sb_shift;
1466
332k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
332k
                        }
1468
1.12M
                        const enum IntraPredMode uv_mode =
1469
1.12M
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
1.12M
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
1.12M
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
1.12M
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
1.12M
                        const enum IntraPredMode m =
1474
1.12M
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
1.12M
                                                              ypos, ypos > ystart,
1476
1.12M
                                                              ts->tiling.col_end >> ss_hor,
1477
1.12M
                                                              ts->tiling.row_end >> ss_ver,
1478
1.12M
                                                              edge_flags, dst, stride,
1479
1.12M
                                                              top_sb_edge, uv_mode,
1480
1.12M
                                                              &angle, uv_t_dim->w,
1481
1.12M
                                                              uv_t_dim->h,
1482
1.12M
                                                              f->seq_hdr->intra_edge_filter,
1483
1.12M
                                                              edge HIGHBD_CALL_SUFFIX);
1484
1.12M
                        angle |= intra_edge_filter_flag;
1485
1.12M
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
1.12M
                                                 uv_t_dim->w * 4,
1487
1.12M
                                                 uv_t_dim->h * 4,
1488
1.12M
                                                 angle | sm_uv_fl,
1489
1.12M
                                                 (4 * f->bw + ss_hor -
1490
1.12M
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
1.12M
                                                 (4 * f->bh + ss_ver -
1492
1.12M
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
1.12M
                                                 HIGHBD_CALL_SUFFIX);
1494
1.12M
                        if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1495
0
                            hex_dump(edge - uv_t_dim->h * 4, uv_t_dim->h * 4,
1496
0
                                     uv_t_dim->h * 4, 2, "l");
1497
0
                            hex_dump(edge, 0, 1, 1, "tl");
1498
0
                            hex_dump(edge + 1, uv_t_dim->w * 4,
1499
0
                                     uv_t_dim->w * 4, 2, "t");
1500
0
                            hex_dump(dst, stride, uv_t_dim->w * 4,
1501
0
                                     uv_t_dim->h * 4, pl ? "v-intra-pred" : "u-intra-pred");
1502
0
                        }
1503
1504
1.24M
                    skip_uv_pred: {}
1505
1.24M
                        if (!b->skip) {
1506
570k
                            enum TxfmType txtp;
1507
570k
                            int eob;
1508
570k
                            coef *cf;
1509
570k
                            if (t->frame_thread.pass) {
1510
570k
                                const int p = t->frame_thread.pass & 1;
1511
570k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
570k
                                cf = ts->frame_thread[p].cf;
1513
570k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
570k
                                eob  = cbi >> 5;
1515
570k
                                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
570k
                            if (eob >= 0) {
1533
148k
                                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
148k
                                dsp->itx.itxfm_add[b->uvtx]
1537
148k
                                                  [txtp](dst, stride,
1538
148k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
148k
                                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
148k
                            }
1543
679k
                        } 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.24M
                        dst += uv_t_dim->w * 4;
1548
1.24M
                    }
1549
1.07M
                    t->bx -= x << ss_hor;
1550
1.07M
                }
1551
971k
                t->by -= y << ss_ver;
1552
971k
            }
1553
486k
        }
1554
613k
    }
1555
585k
}
dav1d_recon_b_intra_8bpc
Line
Count
Source
1179
273k
{
1180
273k
    Dav1dTileState *const ts = t->ts;
1181
273k
    const Dav1dFrameContext *const f = t->f;
1182
273k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
273k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
273k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
273k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
273k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
273k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
273k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
273k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
273k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
273k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
210k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
202k
                           (bh4 > ss_ver || t->by & 1);
1194
273k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
273k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
273k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
273k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
273k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
558k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
285k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
285k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
586k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
300k
            if (b->pal_sz[0]) {
1208
1.89k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
1.89k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
1.89k
                const uint8_t *pal_idx;
1211
1.89k
                if (t->frame_thread.pass) {
1212
1.89k
                    const int p = t->frame_thread.pass & 1;
1213
1.89k
                    assert(ts->frame_thread[p].pal_idx);
1214
1.89k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
1.89k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
1.89k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
1.89k
                const pixel *const pal = t->frame_thread.pass ?
1220
1.89k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
1.89k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
1.89k
                    bytefn(t->scratch.pal)[0];
1223
1.89k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
1.89k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
1.89k
                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.89k
            }
1229
1230
300k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
300k
                                     sm_flag(&t->l, by4) |
1232
300k
                                     intra_edge_filter_flag);
1233
300k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
285k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
300k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
285k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
300k
            int y, x;
1238
300k
            const int sub_w4 = imin(w4, init_x + 16);
1239
695k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
395k
                 y += t_dim->h, t->by += t_dim->h)
1241
395k
            {
1242
395k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
395k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
395k
                                    t->bx + init_x);
1245
961k
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
566k
                     x += t_dim->w, t->bx += t_dim->w)
1247
566k
                {
1248
566k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
564k
                    int angle = b->y_angle;
1251
564k
                    const enum EdgeFlags edge_flags =
1252
564k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
395k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
564k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
311k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
564k
                    const pixel *top_sb_edge = NULL;
1257
564k
                    if (!(t->by & (f->sb_step - 1))) {
1258
100k
                        top_sb_edge = f->ipred_edge[0];
1259
100k
                        const int sby = t->by >> f->sb_shift;
1260
100k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
100k
                    }
1262
564k
                    const enum IntraPredMode m =
1263
564k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
564k
                                                          t->bx > ts->tiling.col_start,
1265
564k
                                                          t->by,
1266
564k
                                                          t->by > ts->tiling.row_start,
1267
564k
                                                          ts->tiling.col_end,
1268
564k
                                                          ts->tiling.row_end,
1269
564k
                                                          edge_flags, dst,
1270
564k
                                                          f->cur.stride[0], top_sb_edge,
1271
564k
                                                          b->y_mode, &angle,
1272
564k
                                                          t_dim->w, t_dim->h,
1273
564k
                                                          f->seq_hdr->intra_edge_filter,
1274
564k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
564k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
564k
                                             t_dim->w * 4, t_dim->h * 4,
1277
564k
                                             angle | intra_flags,
1278
564k
                                             4 * f->bw - 4 * t->bx,
1279
564k
                                             4 * f->bh - 4 * t->by
1280
564k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
564k
                    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
566k
                skip_y_pred: {}
1293
566k
                    if (!b->skip) {
1294
183k
                        coef *cf;
1295
183k
                        int eob;
1296
183k
                        enum TxfmType txtp;
1297
183k
                        if (t->frame_thread.pass) {
1298
183k
                            const int p = t->frame_thread.pass & 1;
1299
183k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
183k
                            cf = ts->frame_thread[p].cf;
1301
183k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
183k
                            eob  = cbi >> 5;
1303
183k
                            txtp = cbi & 0x1f;
1304
183k
                        } 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
183k
                        if (eob >= 0) {
1317
116k
                            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
116k
                            dsp->itx.itxfm_add[b->tx]
1321
116k
                                              [txtp](dst,
1322
116k
                                                     f->cur.stride[0],
1323
116k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
116k
                            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
116k
                        }
1328
383k
                    } 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
566k
                    dst += 4 * t_dim->w;
1333
566k
                }
1334
395k
                t->bx -= x;
1335
395k
            }
1336
300k
            t->by -= y;
1337
1338
300k
            if (!has_chroma) continue;
1339
1340
217k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
217k
            if (b->uv_mode == CFL_PRED) {
1343
36.2k
                assert(!init_x && !init_y);
1344
1345
36.2k
                int16_t *const ac = t->scratch.ac;
1346
36.2k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
36.2k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
36.2k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
36.2k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
36.2k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
36.2k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
36.2k
                const int furthest_r =
1354
36.2k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
36.2k
                const int furthest_b =
1356
36.2k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
36.2k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
36.2k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
36.2k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
36.2k
                                                         cbw4 * 4, cbh4 * 4);
1361
108k
                for (int pl = 0; pl < 2; pl++) {
1362
72.4k
                    if (!b->cfl_alpha[pl]) continue;
1363
56.7k
                    int angle = 0;
1364
56.7k
                    const pixel *top_sb_edge = NULL;
1365
56.7k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
11.0k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
11.0k
                        const int sby = t->by >> f->sb_shift;
1368
11.0k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
11.0k
                    }
1370
56.7k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
56.7k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
56.7k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
56.7k
                    const enum IntraPredMode m =
1374
56.7k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
56.7k
                                                          ypos, ypos > ystart,
1376
56.7k
                                                          ts->tiling.col_end >> ss_hor,
1377
56.7k
                                                          ts->tiling.row_end >> ss_ver,
1378
56.7k
                                                          0, uv_dst[pl], stride,
1379
56.7k
                                                          top_sb_edge, DC_PRED, &angle,
1380
56.7k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
56.7k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
56.7k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
56.7k
                                           uv_t_dim->w * 4,
1384
56.7k
                                           uv_t_dim->h * 4,
1385
56.7k
                                           ac, b->cfl_alpha[pl]
1386
56.7k
                                           HIGHBD_CALL_SUFFIX);
1387
56.7k
                }
1388
36.2k
                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
1389
0
                    ac_dump(ac, 4*cbw4, 4*cbh4, "ac");
1390
0
                    hex_dump(uv_dst[0], stride, cbw4 * 4, cbh4 * 4, "u-cfl-pred");
1391
0
                    hex_dump(uv_dst[1], stride, cbw4 * 4, cbh4 * 4, "v-cfl-pred");
1392
0
                }
1393
181k
            } else if (b->pal_sz[1]) {
1394
507
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
507
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
507
                const pixel (*pal)[8];
1397
507
                const uint8_t *pal_idx;
1398
507
                if (t->frame_thread.pass) {
1399
507
                    const int p = t->frame_thread.pass & 1;
1400
507
                    assert(ts->frame_thread[p].pal_idx);
1401
507
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
507
                                              ((t->bx >> 1) + (t->by & 1))];
1403
507
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
507
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
507
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
507
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
507
                                       f->cur.stride[1], pal[1],
1412
507
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
507
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
507
                                       f->cur.stride[1], pal[2],
1415
507
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
507
                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
507
            }
1425
1426
217k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
217k
                                 sm_uv_flag(&t->l, cby4);
1428
217k
            const int uv_sb_has_tr =
1429
217k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
205k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
217k
            const int uv_sb_has_bl =
1432
217k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
205k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
217k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
652k
            for (int pl = 0; pl < 2; pl++) {
1436
921k
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
486k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
486k
                {
1439
486k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
486k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
486k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.06M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
577k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
577k
                    {
1445
577k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
520k
                            b->pal_sz[1])
1447
58.0k
                        {
1448
58.0k
                            goto skip_uv_pred;
1449
58.0k
                        }
1450
1451
519k
                        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
519k
                        const enum EdgeFlags edge_flags =
1456
519k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
205k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
370k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
519k
                            ((x > (init_x >> ss_hor) ||
1460
428k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
274k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
519k
                        const pixel *top_sb_edge = NULL;
1463
519k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
140k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
140k
                            const int sby = t->by >> f->sb_shift;
1466
140k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
140k
                        }
1468
519k
                        const enum IntraPredMode uv_mode =
1469
519k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
519k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
519k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
519k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
519k
                        const enum IntraPredMode m =
1474
519k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
519k
                                                              ypos, ypos > ystart,
1476
519k
                                                              ts->tiling.col_end >> ss_hor,
1477
519k
                                                              ts->tiling.row_end >> ss_ver,
1478
519k
                                                              edge_flags, dst, stride,
1479
519k
                                                              top_sb_edge, uv_mode,
1480
519k
                                                              &angle, uv_t_dim->w,
1481
519k
                                                              uv_t_dim->h,
1482
519k
                                                              f->seq_hdr->intra_edge_filter,
1483
519k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
519k
                        angle |= intra_edge_filter_flag;
1485
519k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
519k
                                                 uv_t_dim->w * 4,
1487
519k
                                                 uv_t_dim->h * 4,
1488
519k
                                                 angle | sm_uv_fl,
1489
519k
                                                 (4 * f->bw + ss_hor -
1490
519k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
519k
                                                 (4 * f->bh + ss_ver -
1492
519k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
519k
                                                 HIGHBD_CALL_SUFFIX);
1494
519k
                        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
577k
                    skip_uv_pred: {}
1505
577k
                        if (!b->skip) {
1506
264k
                            enum TxfmType txtp;
1507
264k
                            int eob;
1508
264k
                            coef *cf;
1509
264k
                            if (t->frame_thread.pass) {
1510
264k
                                const int p = t->frame_thread.pass & 1;
1511
264k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
264k
                                cf = ts->frame_thread[p].cf;
1513
264k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
264k
                                eob  = cbi >> 5;
1515
264k
                                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
264k
                            if (eob >= 0) {
1533
68.7k
                                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
68.7k
                                dsp->itx.itxfm_add[b->uvtx]
1537
68.7k
                                                  [txtp](dst, stride,
1538
68.7k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
68.7k
                                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
68.7k
                            }
1543
313k
                        } 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
577k
                        dst += uv_t_dim->w * 4;
1548
577k
                    }
1549
486k
                    t->bx -= x << ss_hor;
1550
486k
                }
1551
435k
                t->by -= y << ss_ver;
1552
435k
            }
1553
217k
        }
1554
285k
    }
1555
273k
}
dav1d_recon_b_intra_16bpc
Line
Count
Source
1179
312k
{
1180
312k
    Dav1dTileState *const ts = t->ts;
1181
312k
    const Dav1dFrameContext *const f = t->f;
1182
312k
    const Dav1dDSPContext *const dsp = f->dsp;
1183
312k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1184
312k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1185
312k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1186
312k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1187
312k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1188
312k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1189
312k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1190
312k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1191
312k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1192
248k
                           (bw4 > ss_hor || t->bx & 1) &&
1193
241k
                           (bh4 > ss_ver || t->by & 1);
1194
312k
    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
1195
312k
    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
1196
1197
    // coefficient coding
1198
312k
    pixel *const edge = bitfn(t->scratch.edge) + 128;
1199
312k
    const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
1200
1201
312k
    const int intra_edge_filter_flag = f->seq_hdr->intra_edge_filter << 10;
1202
1203
640k
    for (int init_y = 0; init_y < h4; init_y += 16) {
1204
328k
        const int sub_h4 = imin(h4, 16 + init_y);
1205
328k
        const int sub_ch4 = imin(ch4, (init_y + 16) >> ss_ver);
1206
678k
        for (int init_x = 0; init_x < w4; init_x += 16) {
1207
350k
            if (b->pal_sz[0]) {
1208
1.60k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1209
1.60k
                             4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1210
1.60k
                const uint8_t *pal_idx;
1211
1.60k
                if (t->frame_thread.pass) {
1212
1.60k
                    const int p = t->frame_thread.pass & 1;
1213
1.60k
                    assert(ts->frame_thread[p].pal_idx);
1214
1.60k
                    pal_idx = ts->frame_thread[p].pal_idx;
1215
1.60k
                    ts->frame_thread[p].pal_idx += bw4 * bh4 * 8;
1216
1.60k
                } else {
1217
0
                    pal_idx = t->scratch.pal_idx_y;
1218
0
                }
1219
1.60k
                const pixel *const pal = t->frame_thread.pass ?
1220
1.60k
                    f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1221
1.60k
                                        ((t->bx >> 1) + (t->by & 1))][0] :
1222
1.60k
                    bytefn(t->scratch.pal)[0];
1223
1.60k
                f->dsp->ipred.pal_pred(dst, f->cur.stride[0], pal,
1224
1.60k
                                       pal_idx, bw4 * 4, bh4 * 4);
1225
1.60k
                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.60k
            }
1229
1230
350k
            const int intra_flags = (sm_flag(t->a, bx4) |
1231
350k
                                     sm_flag(&t->l, by4) |
1232
350k
                                     intra_edge_filter_flag);
1233
350k
            const int sb_has_tr = init_x + 16 < w4 ? 1 : init_y ? 0 :
1234
328k
                              intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT;
1235
350k
            const int sb_has_bl = init_x ? 0 : init_y + 16 < h4 ? 1 :
1236
328k
                              intra_edge_flags & EDGE_I444_LEFT_HAS_BOTTOM;
1237
350k
            int y, x;
1238
350k
            const int sub_w4 = imin(w4, init_x + 16);
1239
803k
            for (y = init_y, t->by += init_y; y < sub_h4;
1240
452k
                 y += t_dim->h, t->by += t_dim->h)
1241
453k
            {
1242
453k
                pixel *dst = ((pixel *) f->cur.data[0]) +
1243
453k
                               4 * (t->by * PXSTRIDE(f->cur.stride[0]) +
1244
453k
                                    t->bx + init_x);
1245
1.15M
                for (x = init_x, t->bx += init_x; x < sub_w4;
1246
705k
                     x += t_dim->w, t->bx += t_dim->w)
1247
706k
                {
1248
706k
                    if (b->pal_sz[0]) goto skip_y_pred;
1249
1250
703k
                    int angle = b->y_angle;
1251
703k
                    const enum EdgeFlags edge_flags =
1252
703k
                        (((y > init_y || !sb_has_tr) && (x + t_dim->w >= sub_w4)) ?
1253
513k
                             0 : EDGE_I444_TOP_HAS_RIGHT) |
1254
703k
                        ((x > init_x || (!sb_has_bl && y + t_dim->h >= sub_h4)) ?
1255
419k
                             0 : EDGE_I444_LEFT_HAS_BOTTOM);
1256
703k
                    const pixel *top_sb_edge = NULL;
1257
703k
                    if (!(t->by & (f->sb_step - 1))) {
1258
141k
                        top_sb_edge = f->ipred_edge[0];
1259
141k
                        const int sby = t->by >> f->sb_shift;
1260
141k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1261
141k
                    }
1262
703k
                    const enum IntraPredMode m =
1263
703k
                        bytefn(dav1d_prepare_intra_edges)(t->bx,
1264
703k
                                                          t->bx > ts->tiling.col_start,
1265
703k
                                                          t->by,
1266
703k
                                                          t->by > ts->tiling.row_start,
1267
703k
                                                          ts->tiling.col_end,
1268
703k
                                                          ts->tiling.row_end,
1269
703k
                                                          edge_flags, dst,
1270
703k
                                                          f->cur.stride[0], top_sb_edge,
1271
703k
                                                          b->y_mode, &angle,
1272
703k
                                                          t_dim->w, t_dim->h,
1273
703k
                                                          f->seq_hdr->intra_edge_filter,
1274
703k
                                                          edge HIGHBD_CALL_SUFFIX);
1275
703k
                    dsp->ipred.intra_pred[m](dst, f->cur.stride[0], edge,
1276
703k
                                             t_dim->w * 4, t_dim->h * 4,
1277
703k
                                             angle | intra_flags,
1278
703k
                                             4 * f->bw - 4 * t->bx,
1279
703k
                                             4 * f->bh - 4 * t->by
1280
703k
                                             HIGHBD_CALL_SUFFIX);
1281
1282
703k
                    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
705k
                skip_y_pred: {}
1293
705k
                    if (!b->skip) {
1294
217k
                        coef *cf;
1295
217k
                        int eob;
1296
217k
                        enum TxfmType txtp;
1297
217k
                        if (t->frame_thread.pass) {
1298
217k
                            const int p = t->frame_thread.pass & 1;
1299
217k
                            const int cbi = *ts->frame_thread[p].cbi++;
1300
217k
                            cf = ts->frame_thread[p].cf;
1301
217k
                            ts->frame_thread[p].cf += imin(t_dim->w, 8) * imin(t_dim->h, 8) * 16;
1302
217k
                            eob  = cbi >> 5;
1303
217k
                            txtp = cbi & 0x1f;
1304
217k
                        } 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
217k
                        if (eob >= 0) {
1317
144k
                            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
144k
                            dsp->itx.itxfm_add[b->tx]
1321
144k
                                              [txtp](dst,
1322
144k
                                                     f->cur.stride[0],
1323
144k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1324
144k
                            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
144k
                        }
1328
488k
                    } 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
705k
                    dst += 4 * t_dim->w;
1333
705k
                }
1334
452k
                t->bx -= x;
1335
452k
            }
1336
350k
            t->by -= y;
1337
1338
350k
            if (!has_chroma) continue;
1339
1340
268k
            const ptrdiff_t stride = f->cur.stride[1];
1341
1342
268k
            if (b->uv_mode == CFL_PRED) {
1343
42.3k
                assert(!init_x && !init_y);
1344
1345
42.3k
                int16_t *const ac = t->scratch.ac;
1346
42.3k
                pixel *y_src = ((pixel *) f->cur.data[0]) + 4 * (t->bx & ~ss_hor) +
1347
42.3k
                                 4 * (t->by & ~ss_ver) * PXSTRIDE(f->cur.stride[0]);
1348
42.3k
                const ptrdiff_t uv_off = 4 * ((t->bx >> ss_hor) +
1349
42.3k
                                              (t->by >> ss_ver) * PXSTRIDE(stride));
1350
42.3k
                pixel *const uv_dst[2] = { ((pixel *) f->cur.data[1]) + uv_off,
1351
42.3k
                                           ((pixel *) f->cur.data[2]) + uv_off };
1352
1353
42.3k
                const int furthest_r =
1354
42.3k
                    ((cw4 << ss_hor) + t_dim->w - 1) & ~(t_dim->w - 1);
1355
42.3k
                const int furthest_b =
1356
42.3k
                    ((ch4 << ss_ver) + t_dim->h - 1) & ~(t_dim->h - 1);
1357
42.3k
                dsp->ipred.cfl_ac[f->cur.p.layout - 1](ac, y_src, f->cur.stride[0],
1358
42.3k
                                                         cbw4 - (furthest_r >> ss_hor),
1359
42.3k
                                                         cbh4 - (furthest_b >> ss_ver),
1360
42.3k
                                                         cbw4 * 4, cbh4 * 4);
1361
127k
                for (int pl = 0; pl < 2; pl++) {
1362
84.7k
                    if (!b->cfl_alpha[pl]) continue;
1363
65.5k
                    int angle = 0;
1364
65.5k
                    const pixel *top_sb_edge = NULL;
1365
65.5k
                    if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1366
14.4k
                        top_sb_edge = f->ipred_edge[pl + 1];
1367
14.4k
                        const int sby = t->by >> f->sb_shift;
1368
14.4k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1369
14.4k
                    }
1370
65.5k
                    const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1371
65.5k
                    const int xstart = ts->tiling.col_start >> ss_hor;
1372
65.5k
                    const int ystart = ts->tiling.row_start >> ss_ver;
1373
65.5k
                    const enum IntraPredMode m =
1374
65.5k
                        bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1375
65.5k
                                                          ypos, ypos > ystart,
1376
65.5k
                                                          ts->tiling.col_end >> ss_hor,
1377
65.5k
                                                          ts->tiling.row_end >> ss_ver,
1378
65.5k
                                                          0, uv_dst[pl], stride,
1379
65.5k
                                                          top_sb_edge, DC_PRED, &angle,
1380
65.5k
                                                          uv_t_dim->w, uv_t_dim->h, 0,
1381
65.5k
                                                          edge HIGHBD_CALL_SUFFIX);
1382
65.5k
                    dsp->ipred.cfl_pred[m](uv_dst[pl], stride, edge,
1383
65.5k
                                           uv_t_dim->w * 4,
1384
65.5k
                                           uv_t_dim->h * 4,
1385
65.5k
                                           ac, b->cfl_alpha[pl]
1386
65.5k
                                           HIGHBD_CALL_SUFFIX);
1387
65.5k
                }
1388
42.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
226k
            } else if (b->pal_sz[1]) {
1394
385
                const ptrdiff_t uv_dstoff = 4 * ((t->bx >> ss_hor) +
1395
385
                                              (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1396
385
                const pixel (*pal)[8];
1397
385
                const uint8_t *pal_idx;
1398
385
                if (t->frame_thread.pass) {
1399
385
                    const int p = t->frame_thread.pass & 1;
1400
385
                    assert(ts->frame_thread[p].pal_idx);
1401
385
                    pal = f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1402
385
                                              ((t->bx >> 1) + (t->by & 1))];
1403
385
                    pal_idx = ts->frame_thread[p].pal_idx;
1404
385
                    ts->frame_thread[p].pal_idx += cbw4 * cbh4 * 8;
1405
385
                } else {
1406
0
                    pal = bytefn(t->scratch.pal);
1407
0
                    pal_idx = t->scratch.pal_idx_uv;
1408
0
                }
1409
1410
385
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[1]) + uv_dstoff,
1411
385
                                       f->cur.stride[1], pal[1],
1412
385
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1413
385
                f->dsp->ipred.pal_pred(((pixel *) f->cur.data[2]) + uv_dstoff,
1414
385
                                       f->cur.stride[1], pal[2],
1415
385
                                       pal_idx, cbw4 * 4, cbh4 * 4);
1416
385
                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
385
            }
1425
1426
268k
            const int sm_uv_fl = sm_uv_flag(t->a, cbx4) |
1427
268k
                                 sm_uv_flag(&t->l, cby4);
1428
268k
            const int uv_sb_has_tr =
1429
268k
                ((init_x + 16) >> ss_hor) < cw4 ? 1 : init_y ? 0 :
1430
248k
                intra_edge_flags & (EDGE_I420_TOP_HAS_RIGHT >> (f->cur.p.layout - 1));
1431
268k
            const int uv_sb_has_bl =
1432
268k
                init_x ? 0 : ((init_y + 16) >> ss_ver) < ch4 ? 1 :
1433
248k
                intra_edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM >> (f->cur.p.layout - 1));
1434
268k
            const int sub_cw4 = imin(cw4, (init_x + 16) >> ss_hor);
1435
805k
            for (int pl = 0; pl < 2; pl++) {
1436
1.12M
                for (y = init_y >> ss_ver, t->by += init_y; y < sub_ch4;
1437
585k
                     y += uv_t_dim->h, t->by += uv_t_dim->h << ss_ver)
1438
585k
                {
1439
585k
                    pixel *dst = ((pixel *) f->cur.data[1 + pl]) +
1440
585k
                                   4 * ((t->by >> ss_ver) * PXSTRIDE(stride) +
1441
585k
                                        ((t->bx + init_x) >> ss_hor));
1442
1.25M
                    for (x = init_x >> ss_hor, t->bx += init_x; x < sub_cw4;
1443
672k
                         x += uv_t_dim->w, t->bx += uv_t_dim->w << ss_hor)
1444
672k
                    {
1445
672k
                        if ((b->uv_mode == CFL_PRED && b->cfl_alpha[pl]) ||
1446
607k
                            b->pal_sz[1])
1447
66.3k
                        {
1448
66.3k
                            goto skip_uv_pred;
1449
66.3k
                        }
1450
1451
606k
                        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
606k
                        const enum EdgeFlags edge_flags =
1456
606k
                            (((y > (init_y >> ss_ver) || !uv_sb_has_tr) &&
1457
214k
                              (x + uv_t_dim->w >= sub_cw4)) ?
1458
439k
                                 0 : EDGE_I444_TOP_HAS_RIGHT) |
1459
606k
                            ((x > (init_x >> ss_hor) ||
1460
519k
                              (!uv_sb_has_bl && y + uv_t_dim->h >= sub_ch4)) ?
1461
316k
                                 0 : EDGE_I444_LEFT_HAS_BOTTOM);
1462
606k
                        const pixel *top_sb_edge = NULL;
1463
606k
                        if (!((t->by & ~ss_ver) & (f->sb_step - 1))) {
1464
191k
                            top_sb_edge = f->ipred_edge[1 + pl];
1465
191k
                            const int sby = t->by >> f->sb_shift;
1466
191k
                            top_sb_edge += f->sb128w * 128 * (sby - 1);
1467
191k
                        }
1468
606k
                        const enum IntraPredMode uv_mode =
1469
606k
                             b->uv_mode == CFL_PRED ? DC_PRED : b->uv_mode;
1470
606k
                        const int xpos = t->bx >> ss_hor, ypos = t->by >> ss_ver;
1471
606k
                        const int xstart = ts->tiling.col_start >> ss_hor;
1472
606k
                        const int ystart = ts->tiling.row_start >> ss_ver;
1473
606k
                        const enum IntraPredMode m =
1474
606k
                            bytefn(dav1d_prepare_intra_edges)(xpos, xpos > xstart,
1475
606k
                                                              ypos, ypos > ystart,
1476
606k
                                                              ts->tiling.col_end >> ss_hor,
1477
606k
                                                              ts->tiling.row_end >> ss_ver,
1478
606k
                                                              edge_flags, dst, stride,
1479
606k
                                                              top_sb_edge, uv_mode,
1480
606k
                                                              &angle, uv_t_dim->w,
1481
606k
                                                              uv_t_dim->h,
1482
606k
                                                              f->seq_hdr->intra_edge_filter,
1483
606k
                                                              edge HIGHBD_CALL_SUFFIX);
1484
606k
                        angle |= intra_edge_filter_flag;
1485
606k
                        dsp->ipred.intra_pred[m](dst, stride, edge,
1486
606k
                                                 uv_t_dim->w * 4,
1487
606k
                                                 uv_t_dim->h * 4,
1488
606k
                                                 angle | sm_uv_fl,
1489
606k
                                                 (4 * f->bw + ss_hor -
1490
606k
                                                  4 * (t->bx & ~ss_hor)) >> ss_hor,
1491
606k
                                                 (4 * f->bh + ss_ver -
1492
606k
                                                  4 * (t->by & ~ss_ver)) >> ss_ver
1493
606k
                                                 HIGHBD_CALL_SUFFIX);
1494
606k
                        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
672k
                    skip_uv_pred: {}
1505
672k
                        if (!b->skip) {
1506
306k
                            enum TxfmType txtp;
1507
306k
                            int eob;
1508
306k
                            coef *cf;
1509
306k
                            if (t->frame_thread.pass) {
1510
306k
                                const int p = t->frame_thread.pass & 1;
1511
306k
                                const int cbi = *ts->frame_thread[p].cbi++;
1512
306k
                                cf = ts->frame_thread[p].cf;
1513
306k
                                ts->frame_thread[p].cf += uv_t_dim->w * uv_t_dim->h * 16;
1514
306k
                                eob  = cbi >> 5;
1515
306k
                                txtp = cbi & 0x1f;
1516
306k
                            } 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
306k
                            if (eob >= 0) {
1533
79.7k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1534
0
                                    coef_dump(cf, uv_t_dim->h * 4,
1535
0
                                              uv_t_dim->w * 4, 3, "dq");
1536
79.7k
                                dsp->itx.itxfm_add[b->uvtx]
1537
79.7k
                                                  [txtp](dst, stride,
1538
79.7k
                                                         cf, eob HIGHBD_CALL_SUFFIX);
1539
79.7k
                                if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1540
0
                                    hex_dump(dst, stride, uv_t_dim->w * 4,
1541
0
                                             uv_t_dim->h * 4, "recon");
1542
79.7k
                            }
1543
366k
                        } 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
672k
                        dst += uv_t_dim->w * 4;
1548
672k
                    }
1549
585k
                    t->bx -= x << ss_hor;
1550
585k
                }
1551
536k
                t->by -= y << ss_ver;
1552
536k
            }
1553
268k
        }
1554
328k
    }
1555
312k
}
1556
1557
int bytefn(dav1d_recon_b_inter)(Dav1dTaskContext *const t, const enum BlockSize bs,
1558
                                const Av1Block *const b)
1559
131k
{
1560
131k
    Dav1dTileState *const ts = t->ts;
1561
131k
    const Dav1dFrameContext *const f = t->f;
1562
131k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
131k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
131k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
131k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
131k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
131k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
131k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
131k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
131k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
104k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
99.4k
                           (bh4 > ss_ver || t->by & 1);
1573
131k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
131k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
131k
    int res;
1576
1577
    // prediction
1578
131k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
131k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
131k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
131k
    const ptrdiff_t uvdstoff =
1582
131k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
131k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
39.0k
        assert(!f->frame_hdr->super_res.enabled);
1586
39.0k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
39.0k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
39.0k
        if (res) return res;
1589
110k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
73.8k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
73.8k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
73.8k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
73.8k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
73.8k
            if (res) return res;
1595
73.8k
        }
1596
92.4k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
84.1k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
84.1k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
84.1k
        if (imin(bw4, bh4) > 1 &&
1601
57.4k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
56.1k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
1.65k
        {
1604
1.65k
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
1.65k
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
1.65k
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
1.65k
            if (res) return res;
1608
82.5k
        } else {
1609
82.5k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
82.5k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
82.5k
            if (res) return res;
1612
82.5k
            if (b->motion_mode == MM_OBMC) {
1613
19.4k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
19.4k
                if (res) return res;
1615
19.4k
            }
1616
82.5k
        }
1617
84.1k
        if (b->interintra_type) {
1618
2.30k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
2.30k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.88k
                                   SMOOTH_PRED : b->interintra_mode;
1621
2.30k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
2.30k
            int angle = 0;
1623
2.30k
            const pixel *top_sb_edge = NULL;
1624
2.30k
            if (!(t->by & (f->sb_step - 1))) {
1625
742
                top_sb_edge = f->ipred_edge[0];
1626
742
                const int sby = t->by >> f->sb_shift;
1627
742
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
742
            }
1629
2.30k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
2.30k
                                                  t->by, t->by > ts->tiling.row_start,
1631
2.30k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
2.30k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
2.30k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
2.30k
                                                  HIGHBD_CALL_SUFFIX);
1635
2.30k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
2.30k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
2.30k
                                     HIGHBD_CALL_SUFFIX);
1638
2.30k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
2.30k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
2.30k
        }
1641
1642
84.1k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
52.0k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
52.0k
        refmvs_block *const *r;
1647
52.0k
        if (is_sub8x8) {
1648
7.69k
            assert(ss_hor == 1);
1649
7.69k
            r = &t->rt.r[(t->by & 31) + 5];
1650
7.69k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
7.69k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
7.69k
            if (bw4 == 1 && bh4 == ss_ver)
1653
1.00k
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
7.69k
        }
1655
1656
        // chroma prediction
1657
52.0k
        if (is_sub8x8) {
1658
7.57k
            assert(ss_hor == 1);
1659
7.57k
            ptrdiff_t h_off = 0, v_off = 0;
1660
7.57k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
2.93k
                for (int pl = 0; pl < 2; pl++) {
1662
1.95k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.95k
                             NULL, f->cur.stride[1],
1664
1.95k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.95k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.95k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.95k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.95k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.95k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.95k
                    if (res) return res;
1671
1.95k
                }
1672
979
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
979
                h_off = 2;
1674
979
            }
1675
7.57k
            if (bw4 == 1) {
1676
4.04k
                const enum Filter2d left_filter_2d =
1677
4.04k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
12.1k
                for (int pl = 0; pl < 2; pl++) {
1679
8.09k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
8.09k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
8.09k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
8.09k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
8.09k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
8.09k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
8.09k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
8.09k
                    if (res) return res;
1687
8.09k
                }
1688
4.04k
                h_off = 2;
1689
4.04k
            }
1690
7.57k
            if (bh4 == ss_ver) {
1691
4.50k
                const enum Filter2d top_filter_2d =
1692
4.50k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
13.5k
                for (int pl = 0; pl < 2; pl++) {
1694
9.01k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
9.01k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
9.01k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
9.01k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
9.01k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
9.01k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
9.01k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
9.01k
                    if (res) return res;
1702
9.01k
                }
1703
4.50k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
4.50k
            }
1705
22.7k
            for (int pl = 0; pl < 2; pl++) {
1706
15.1k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
15.1k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
15.1k
                         refp, b->ref[0], filter_2d);
1709
15.1k
                if (res) return res;
1710
15.1k
            }
1711
44.5k
        } else {
1712
44.5k
            if (imin(cbw4, cbh4) > 1 &&
1713
20.8k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
20.1k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
801
            {
1716
2.40k
                for (int pl = 0; pl < 2; pl++) {
1717
1.60k
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
1.60k
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
1.60k
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
1.60k
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
1.60k
                    if (res) return res;
1722
1.60k
                }
1723
43.7k
            } else {
1724
131k
                for (int pl = 0; pl < 2; pl++) {
1725
87.3k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
87.3k
                             NULL, f->cur.stride[1],
1727
87.3k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
87.3k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
87.3k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
87.3k
                    if (res) return res;
1731
87.3k
                    if (b->motion_mode == MM_OBMC) {
1732
29.1k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
29.1k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
29.1k
                        if (res) return res;
1735
29.1k
                    }
1736
87.3k
                }
1737
43.7k
            }
1738
44.5k
            if (b->interintra_type) {
1739
                // FIXME for 8x32 with 4:2:2 subsampling, this probably does
1740
                // the wrong thing since it will select 4x16, not 4x32, as a
1741
                // transform size...
1742
1.79k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
5.37k
                for (int pl = 0; pl < 2; pl++) {
1745
3.58k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
3.58k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
3.58k
                    enum IntraPredMode m =
1748
3.58k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
2.92k
                        SMOOTH_PRED : b->interintra_mode;
1750
3.58k
                    int angle = 0;
1751
3.58k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
3.58k
                    const pixel *top_sb_edge = NULL;
1753
3.58k
                    if (!(t->by & (f->sb_step - 1))) {
1754
1.02k
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
1.02k
                        const int sby = t->by >> f->sb_shift;
1756
1.02k
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
1.02k
                    }
1758
3.58k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
3.58k
                                                          (t->bx >> ss_hor) >
1760
3.58k
                                                              (ts->tiling.col_start >> ss_hor),
1761
3.58k
                                                          t->by >> ss_ver,
1762
3.58k
                                                          (t->by >> ss_ver) >
1763
3.58k
                                                              (ts->tiling.row_start >> ss_ver),
1764
3.58k
                                                          ts->tiling.col_end >> ss_hor,
1765
3.58k
                                                          ts->tiling.row_end >> ss_ver,
1766
3.58k
                                                          0, uvdst, f->cur.stride[1],
1767
3.58k
                                                          top_sb_edge, m,
1768
3.58k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
3.58k
                                                          HIGHBD_CALL_SUFFIX);
1770
3.58k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
3.58k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
3.58k
                                             HIGHBD_CALL_SUFFIX);
1773
3.58k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
3.58k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
3.58k
                }
1776
1.79k
            }
1777
44.5k
        }
1778
1779
84.1k
    skip_inter_chroma_pred: {}
1780
84.1k
        t->tl_4x4_filter = filter_2d;
1781
84.1k
    } else {
1782
8.25k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
8.25k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
8.25k
        int jnt_weight;
1786
8.25k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
8.25k
        const uint8_t *mask;
1788
1789
24.7k
        for (int i = 0; i < 2; i++) {
1790
16.5k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
16.5k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
196
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
196
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
196
                if (res) return res;
1796
16.3k
            } else {
1797
16.3k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
16.3k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
16.3k
                if (res) return res;
1800
16.3k
            }
1801
16.5k
        }
1802
8.25k
        switch (b->comp_type) {
1803
6.19k
        case COMP_INTER_AVG:
1804
6.19k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
6.19k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
6.19k
            break;
1807
571
        case COMP_INTER_WEIGHTED_AVG:
1808
571
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
571
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
571
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
571
            break;
1812
1.00k
        case COMP_INTER_SEG:
1813
1.00k
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
1.00k
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
1.00k
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
1.00k
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
1.00k
            mask = seg_mask;
1818
1.00k
            break;
1819
488
        case COMP_INTER_WEDGE:
1820
488
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
488
            dsp->mc.mask(dst, f->cur.stride[0],
1822
488
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
488
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
488
            if (has_chroma)
1825
363
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
488
            break;
1827
8.25k
        }
1828
1829
        // chroma
1830
17.5k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
35.0k
            for (int i = 0; i < 2; i++) {
1832
23.3k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
23.3k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
2.76k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
120
                {
1836
120
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
120
                                      b_dim, 1 + pl,
1838
120
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
120
                    if (res) return res;
1840
23.2k
                } else {
1841
23.2k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
23.2k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
23.2k
                    if (res) return res;
1844
23.2k
                }
1845
23.3k
            }
1846
11.6k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
11.6k
            switch (b->comp_type) {
1848
9.30k
            case COMP_INTER_AVG:
1849
9.30k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
9.30k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
9.30k
                            HIGHBD_CALL_SUFFIX);
1852
9.30k
                break;
1853
298
            case COMP_INTER_WEIGHTED_AVG:
1854
298
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
298
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
298
                              HIGHBD_CALL_SUFFIX);
1857
298
                break;
1858
726
            case COMP_INTER_WEDGE:
1859
2.07k
            case COMP_INTER_SEG:
1860
2.07k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
2.07k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
2.07k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
2.07k
                             HIGHBD_CALL_SUFFIX);
1864
2.07k
                break;
1865
11.6k
            }
1866
11.6k
        }
1867
8.25k
    }
1868
1869
131k
    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
131k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
131k
    if (b->skip) {
1882
        // reset coef contexts
1883
64.7k
        BlockContext *const a = t->a;
1884
64.7k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
64.7k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
64.7k
        if (has_chroma) {
1887
43.6k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
43.6k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
43.6k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
43.6k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
43.6k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
43.6k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
43.6k
        }
1894
64.7k
        return 0;
1895
64.7k
    }
1896
1897
66.7k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
66.7k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
66.7k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
135k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
140k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
72.1k
            int y_off = !!init_y, y;
1905
72.1k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
150k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
78.1k
                 y += ytx->h, y_off++)
1908
78.1k
            {
1909
78.1k
                int x, x_off = !!init_x;
1910
175k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
97.6k
                     x += ytx->w, x_off++)
1912
97.6k
                {
1913
97.6k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
97.6k
                                   x_off, y_off, &dst[x * 4]);
1915
97.6k
                    t->bx += ytx->w;
1916
97.6k
                }
1917
78.1k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
78.1k
                t->bx -= x;
1919
78.1k
                t->by += ytx->h;
1920
78.1k
            }
1921
72.1k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
72.1k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
165k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
110k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
110k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
110k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
233k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
123k
                {
1931
123k
                    int x;
1932
123k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
272k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
149k
                    {
1935
149k
                        coef *cf;
1936
149k
                        int eob;
1937
149k
                        enum TxfmType txtp;
1938
149k
                        if (t->frame_thread.pass) {
1939
149k
                            const int p = t->frame_thread.pass & 1;
1940
149k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
149k
                            cf = ts->frame_thread[p].cf;
1942
149k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
149k
                            eob  = cbi >> 5;
1944
149k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
149k
                        if (eob >= 0) {
1964
45.5k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
45.5k
                            dsp->itx.itxfm_add[b->uvtx]
1967
45.5k
                                              [txtp](&uvdst[4 * x],
1968
45.5k
                                                     f->cur.stride[1],
1969
45.5k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
45.5k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
45.5k
                        }
1974
149k
                        t->bx += uvtx->w << ss_hor;
1975
149k
                    }
1976
123k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
123k
                    t->bx -= x << ss_hor;
1978
123k
                    t->by += uvtx->h << ss_ver;
1979
123k
                }
1980
110k
                t->by -= y << ss_ver;
1981
110k
            }
1982
72.1k
        }
1983
68.6k
    }
1984
66.7k
    return 0;
1985
131k
}
dav1d_recon_b_inter_8bpc
Line
Count
Source
1559
63.6k
{
1560
63.6k
    Dav1dTileState *const ts = t->ts;
1561
63.6k
    const Dav1dFrameContext *const f = t->f;
1562
63.6k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
63.6k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
63.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
63.6k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
63.6k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
63.6k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
63.6k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
63.6k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
63.6k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
47.3k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
45.2k
                           (bh4 > ss_ver || t->by & 1);
1573
63.6k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
63.6k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
63.6k
    int res;
1576
1577
    // prediction
1578
63.6k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
63.6k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
63.6k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
63.6k
    const ptrdiff_t uvdstoff =
1582
63.6k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
63.6k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
20.3k
        assert(!f->frame_hdr->super_res.enabled);
1586
20.3k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
20.3k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
20.3k
        if (res) return res;
1589
60.5k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
40.3k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
40.3k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
40.3k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
40.3k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
40.3k
            if (res) return res;
1595
40.3k
        }
1596
43.3k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
39.5k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
39.5k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
39.5k
        if (imin(bw4, bh4) > 1 &&
1601
26.6k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
25.8k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
949
        {
1604
949
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
949
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
949
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
949
            if (res) return res;
1608
38.6k
        } else {
1609
38.6k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
38.6k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
38.6k
            if (res) return res;
1612
38.6k
            if (b->motion_mode == MM_OBMC) {
1613
9.13k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
9.13k
                if (res) return res;
1615
9.13k
            }
1616
38.6k
        }
1617
39.5k
        if (b->interintra_type) {
1618
863
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
863
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
709
                                   SMOOTH_PRED : b->interintra_mode;
1621
863
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
863
            int angle = 0;
1623
863
            const pixel *top_sb_edge = NULL;
1624
863
            if (!(t->by & (f->sb_step - 1))) {
1625
283
                top_sb_edge = f->ipred_edge[0];
1626
283
                const int sby = t->by >> f->sb_shift;
1627
283
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
283
            }
1629
863
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
863
                                                  t->by, t->by > ts->tiling.row_start,
1631
863
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
863
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
863
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
863
                                                  HIGHBD_CALL_SUFFIX);
1635
863
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
863
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
863
                                     HIGHBD_CALL_SUFFIX);
1638
863
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
863
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
863
        }
1641
1642
39.5k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
20.4k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
20.4k
        refmvs_block *const *r;
1647
20.4k
        if (is_sub8x8) {
1648
3.19k
            assert(ss_hor == 1);
1649
3.19k
            r = &t->rt.r[(t->by & 31) + 5];
1650
3.19k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
3.19k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
3.19k
            if (bw4 == 1 && bh4 == ss_ver)
1653
386
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
3.19k
        }
1655
1656
        // chroma prediction
1657
20.4k
        if (is_sub8x8) {
1658
3.15k
            assert(ss_hor == 1);
1659
3.15k
            ptrdiff_t h_off = 0, v_off = 0;
1660
3.15k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.12k
                for (int pl = 0; pl < 2; pl++) {
1662
750
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
750
                             NULL, f->cur.stride[1],
1664
750
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
750
                             r[-1][t->bx - 1].mv.mv[0],
1666
750
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
750
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
750
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
750
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
750
                    if (res) return res;
1671
750
                }
1672
375
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
375
                h_off = 2;
1674
375
            }
1675
3.15k
            if (bw4 == 1) {
1676
1.67k
                const enum Filter2d left_filter_2d =
1677
1.67k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
5.02k
                for (int pl = 0; pl < 2; pl++) {
1679
3.35k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
3.35k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
3.35k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
3.35k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
3.35k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
3.35k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
3.35k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
3.35k
                    if (res) return res;
1687
3.35k
                }
1688
1.67k
                h_off = 2;
1689
1.67k
            }
1690
3.15k
            if (bh4 == ss_ver) {
1691
1.85k
                const enum Filter2d top_filter_2d =
1692
1.85k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
5.56k
                for (int pl = 0; pl < 2; pl++) {
1694
3.70k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
3.70k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
3.70k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
3.70k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
3.70k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
3.70k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
3.70k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
3.70k
                    if (res) return res;
1702
3.70k
                }
1703
1.85k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
1.85k
            }
1705
9.46k
            for (int pl = 0; pl < 2; pl++) {
1706
6.31k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
6.31k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
6.31k
                         refp, b->ref[0], filter_2d);
1709
6.31k
                if (res) return res;
1710
6.31k
            }
1711
17.2k
        } else {
1712
17.2k
            if (imin(cbw4, cbh4) > 1 &&
1713
6.91k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
6.49k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
475
            {
1716
1.42k
                for (int pl = 0; pl < 2; pl++) {
1717
950
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
950
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
950
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
950
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
950
                    if (res) return res;
1722
950
                }
1723
16.8k
            } else {
1724
50.4k
                for (int pl = 0; pl < 2; pl++) {
1725
33.6k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
33.6k
                             NULL, f->cur.stride[1],
1727
33.6k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
33.6k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
33.6k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
33.6k
                    if (res) return res;
1731
33.6k
                    if (b->motion_mode == MM_OBMC) {
1732
10.1k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
10.1k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
10.1k
                        if (res) return res;
1735
10.1k
                    }
1736
33.6k
                }
1737
16.8k
            }
1738
17.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
490
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
1.47k
                for (int pl = 0; pl < 2; pl++) {
1745
980
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
980
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
980
                    enum IntraPredMode m =
1748
980
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
808
                        SMOOTH_PRED : b->interintra_mode;
1750
980
                    int angle = 0;
1751
980
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
980
                    const pixel *top_sb_edge = NULL;
1753
980
                    if (!(t->by & (f->sb_step - 1))) {
1754
270
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
270
                        const int sby = t->by >> f->sb_shift;
1756
270
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
270
                    }
1758
980
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
980
                                                          (t->bx >> ss_hor) >
1760
980
                                                              (ts->tiling.col_start >> ss_hor),
1761
980
                                                          t->by >> ss_ver,
1762
980
                                                          (t->by >> ss_ver) >
1763
980
                                                              (ts->tiling.row_start >> ss_ver),
1764
980
                                                          ts->tiling.col_end >> ss_hor,
1765
980
                                                          ts->tiling.row_end >> ss_ver,
1766
980
                                                          0, uvdst, f->cur.stride[1],
1767
980
                                                          top_sb_edge, m,
1768
980
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
980
                                                          HIGHBD_CALL_SUFFIX);
1770
980
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
980
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
980
                                             HIGHBD_CALL_SUFFIX);
1773
980
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
980
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
980
                }
1776
490
            }
1777
17.2k
        }
1778
1779
39.5k
    skip_inter_chroma_pred: {}
1780
39.5k
        t->tl_4x4_filter = filter_2d;
1781
39.5k
    } else {
1782
3.75k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
3.75k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
3.75k
        int jnt_weight;
1786
3.75k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
3.75k
        const uint8_t *mask;
1788
1789
11.2k
        for (int i = 0; i < 2; i++) {
1790
7.50k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
7.50k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
93
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
93
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
93
                if (res) return res;
1796
7.40k
            } else {
1797
7.40k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
7.40k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
7.40k
                if (res) return res;
1800
7.40k
            }
1801
7.50k
        }
1802
3.75k
        switch (b->comp_type) {
1803
2.86k
        case COMP_INTER_AVG:
1804
2.86k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
2.86k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
2.86k
            break;
1807
273
        case COMP_INTER_WEIGHTED_AVG:
1808
273
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
273
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
273
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
273
            break;
1812
436
        case COMP_INTER_SEG:
1813
436
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
436
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
436
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
436
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
436
            mask = seg_mask;
1818
436
            break;
1819
175
        case COMP_INTER_WEDGE:
1820
175
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
175
            dsp->mc.mask(dst, f->cur.stride[0],
1822
175
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
175
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
175
            if (has_chroma)
1825
126
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
175
            break;
1827
3.75k
        }
1828
1829
        // chroma
1830
8.04k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
16.0k
            for (int i = 0; i < 2; i++) {
1832
10.7k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
10.7k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
1.15k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
74
                {
1836
74
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
74
                                      b_dim, 1 + pl,
1838
74
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
74
                    if (res) return res;
1840
10.6k
                } else {
1841
10.6k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
10.6k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
10.6k
                    if (res) return res;
1844
10.6k
                }
1845
10.7k
            }
1846
5.36k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
5.36k
            switch (b->comp_type) {
1848
4.48k
            case COMP_INTER_AVG:
1849
4.48k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
4.48k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
4.48k
                            HIGHBD_CALL_SUFFIX);
1852
4.48k
                break;
1853
82
            case COMP_INTER_WEIGHTED_AVG:
1854
82
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
82
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
82
                              HIGHBD_CALL_SUFFIX);
1857
82
                break;
1858
252
            case COMP_INTER_WEDGE:
1859
796
            case COMP_INTER_SEG:
1860
796
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
796
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
796
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
796
                             HIGHBD_CALL_SUFFIX);
1864
796
                break;
1865
5.36k
            }
1866
5.36k
        }
1867
3.75k
    }
1868
1869
63.6k
    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
63.6k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
63.6k
    if (b->skip) {
1882
        // reset coef contexts
1883
31.5k
        BlockContext *const a = t->a;
1884
31.5k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
31.5k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
31.5k
        if (has_chroma) {
1887
18.2k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
18.2k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
18.2k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
18.2k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
18.2k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
18.2k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
18.2k
        }
1894
31.5k
        return 0;
1895
31.5k
    }
1896
1897
32.0k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
32.0k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
32.0k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
65.3k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
68.5k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
35.3k
            int y_off = !!init_y, y;
1905
35.3k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
73.4k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
38.0k
                 y += ytx->h, y_off++)
1908
38.0k
            {
1909
38.0k
                int x, x_off = !!init_x;
1910
84.7k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
46.7k
                     x += ytx->w, x_off++)
1912
46.7k
                {
1913
46.7k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
46.7k
                                   x_off, y_off, &dst[x * 4]);
1915
46.7k
                    t->bx += ytx->w;
1916
46.7k
                }
1917
38.0k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
38.0k
                t->bx -= x;
1919
38.0k
                t->by += ytx->h;
1920
38.0k
            }
1921
35.3k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
35.3k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
82.3k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
54.8k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
54.8k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
54.8k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
116k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
61.9k
                {
1931
61.9k
                    int x;
1932
61.9k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
136k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
75.0k
                    {
1935
75.0k
                        coef *cf;
1936
75.0k
                        int eob;
1937
75.0k
                        enum TxfmType txtp;
1938
75.0k
                        if (t->frame_thread.pass) {
1939
75.0k
                            const int p = t->frame_thread.pass & 1;
1940
75.0k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
75.0k
                            cf = ts->frame_thread[p].cf;
1942
75.0k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
75.0k
                            eob  = cbi >> 5;
1944
75.0k
                            txtp = cbi & 0x1f;
1945
75.0k
                        } 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
75.0k
                        if (eob >= 0) {
1964
26.6k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
26.6k
                            dsp->itx.itxfm_add[b->uvtx]
1967
26.6k
                                              [txtp](&uvdst[4 * x],
1968
26.6k
                                                     f->cur.stride[1],
1969
26.6k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
26.6k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1971
0
                                hex_dump(&uvdst[4 * x], f->cur.stride[1],
1972
0
                                         uvtx->w * 4, uvtx->h * 4, "recon");
1973
26.6k
                        }
1974
75.0k
                        t->bx += uvtx->w << ss_hor;
1975
75.0k
                    }
1976
61.9k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
61.9k
                    t->bx -= x << ss_hor;
1978
61.9k
                    t->by += uvtx->h << ss_ver;
1979
61.9k
                }
1980
54.8k
                t->by -= y << ss_ver;
1981
54.8k
            }
1982
35.3k
        }
1983
33.2k
    }
1984
32.0k
    return 0;
1985
63.6k
}
dav1d_recon_b_inter_16bpc
Line
Count
Source
1559
67.8k
{
1560
67.8k
    Dav1dTileState *const ts = t->ts;
1561
67.8k
    const Dav1dFrameContext *const f = t->f;
1562
67.8k
    const Dav1dDSPContext *const dsp = f->dsp;
1563
67.8k
    const int bx4 = t->bx & 31, by4 = t->by & 31;
1564
67.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1565
67.8k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
1566
67.8k
    const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
1567
67.8k
    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
1568
67.8k
    const int bw4 = b_dim[0], bh4 = b_dim[1];
1569
67.8k
    const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
1570
67.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400 &&
1571
57.3k
                           (bw4 > ss_hor || t->bx & 1) &&
1572
54.2k
                           (bh4 > ss_ver || t->by & 1);
1573
67.8k
    const int chr_layout_idx = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I400 ? 0 :
1574
67.8k
                               DAV1D_PIXEL_LAYOUT_I444 - f->cur.p.layout;
1575
67.8k
    int res;
1576
1577
    // prediction
1578
67.8k
    const int cbh4 = (bh4 + ss_ver) >> ss_ver, cbw4 = (bw4 + ss_hor) >> ss_hor;
1579
67.8k
    pixel *dst = ((pixel *) f->cur.data[0]) +
1580
67.8k
        4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx);
1581
67.8k
    const ptrdiff_t uvdstoff =
1582
67.8k
        4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1]));
1583
67.8k
    if (IS_KEY_OR_INTRA(f->frame_hdr)) {
1584
        // intrabc
1585
18.7k
        assert(!f->frame_hdr->super_res.enabled);
1586
18.7k
        res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0,
1587
18.7k
                 b->mv[0], &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1588
18.7k
        if (res) return res;
1589
50.2k
        if (has_chroma) for (int pl = 1; pl < 3; pl++) {
1590
33.4k
            res = mc(t, ((pixel *)f->cur.data[pl]) + uvdstoff, NULL, f->cur.stride[1],
1591
33.4k
                     bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1592
33.4k
                     t->bx & ~ss_hor, t->by & ~ss_ver, pl, b->mv[0],
1593
33.4k
                     &f->sr_cur, 0 /* unused */, FILTER_2D_BILINEAR);
1594
33.4k
            if (res) return res;
1595
33.4k
        }
1596
49.1k
    } else if (b->comp_type == COMP_INTER_NONE) {
1597
44.6k
        const Dav1dThreadPicture *const refp = &f->refp[b->ref[0]];
1598
44.6k
        const enum Filter2d filter_2d = b->filter2d;
1599
1600
44.6k
        if (imin(bw4, bh4) > 1 &&
1601
30.8k
            ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1602
30.3k
             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1603
701
        {
1604
701
            res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
1605
701
                              b->motion_mode == MM_WARP ? &t->warpmv :
1606
701
                                  &f->frame_hdr->gmv[b->ref[0]]);
1607
701
            if (res) return res;
1608
43.9k
        } else {
1609
43.9k
            res = mc(t, dst, NULL, f->cur.stride[0],
1610
43.9k
                     bw4, bh4, t->bx, t->by, 0, b->mv[0], refp, b->ref[0], filter_2d);
1611
43.9k
            if (res) return res;
1612
43.9k
            if (b->motion_mode == MM_OBMC) {
1613
10.3k
                res = obmc(t, dst, f->cur.stride[0], b_dim, 0, bx4, by4, w4, h4);
1614
10.3k
                if (res) return res;
1615
10.3k
            }
1616
43.9k
        }
1617
44.6k
        if (b->interintra_type) {
1618
1.44k
            pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1619
1.44k
            enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
1620
1.17k
                                   SMOOTH_PRED : b->interintra_mode;
1621
1.44k
            pixel *const tmp = bitfn(t->scratch.interintra);
1622
1.44k
            int angle = 0;
1623
1.44k
            const pixel *top_sb_edge = NULL;
1624
1.44k
            if (!(t->by & (f->sb_step - 1))) {
1625
459
                top_sb_edge = f->ipred_edge[0];
1626
459
                const int sby = t->by >> f->sb_shift;
1627
459
                top_sb_edge += f->sb128w * 128 * (sby - 1);
1628
459
            }
1629
1.44k
            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
1630
1.44k
                                                  t->by, t->by > ts->tiling.row_start,
1631
1.44k
                                                  ts->tiling.col_end, ts->tiling.row_end,
1632
1.44k
                                                  0, dst, f->cur.stride[0], top_sb_edge,
1633
1.44k
                                                  m, &angle, bw4, bh4, 0, tl_edge
1634
1.44k
                                                  HIGHBD_CALL_SUFFIX);
1635
1.44k
            dsp->ipred.intra_pred[m](tmp, 4 * bw4 * sizeof(pixel),
1636
1.44k
                                     tl_edge, bw4 * 4, bh4 * 4, 0, 0, 0
1637
1.44k
                                     HIGHBD_CALL_SUFFIX);
1638
1.44k
            dsp->mc.blend(dst, f->cur.stride[0], tmp,
1639
1.44k
                          bw4 * 4, bh4 * 4, II_MASK(0, bs, b));
1640
1.44k
        }
1641
1642
44.6k
        if (!has_chroma) goto skip_inter_chroma_pred;
1643
1644
        // sub8x8 derivation
1645
31.6k
        int is_sub8x8 = bw4 == ss_hor || bh4 == ss_ver;
1646
31.6k
        refmvs_block *const *r;
1647
31.6k
        if (is_sub8x8) {
1648
4.50k
            assert(ss_hor == 1);
1649
4.50k
            r = &t->rt.r[(t->by & 31) + 5];
1650
4.50k
            if (bw4 == 1) is_sub8x8 &= r[0][t->bx - 1].ref.ref[0] > 0;
1651
4.50k
            if (bh4 == ss_ver) is_sub8x8 &= r[-1][t->bx].ref.ref[0] > 0;
1652
4.50k
            if (bw4 == 1 && bh4 == ss_ver)
1653
623
                is_sub8x8 &= r[-1][t->bx - 1].ref.ref[0] > 0;
1654
4.50k
        }
1655
1656
        // chroma prediction
1657
31.6k
        if (is_sub8x8) {
1658
4.42k
            assert(ss_hor == 1);
1659
4.42k
            ptrdiff_t h_off = 0, v_off = 0;
1660
4.42k
            if (bw4 == 1 && bh4 == ss_ver) {
1661
1.81k
                for (int pl = 0; pl < 2; pl++) {
1662
1.20k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1663
1.20k
                             NULL, f->cur.stride[1],
1664
1.20k
                             bw4, bh4, t->bx - 1, t->by - 1, 1 + pl,
1665
1.20k
                             r[-1][t->bx - 1].mv.mv[0],
1666
1.20k
                             &f->refp[r[-1][t->bx - 1].ref.ref[0] - 1],
1667
1.20k
                             r[-1][t->bx - 1].ref.ref[0] - 1,
1668
1.20k
                             t->frame_thread.pass != 2 ? t->tl_4x4_filter :
1669
1.20k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx - 1].filter2d);
1670
1.20k
                    if (res) return res;
1671
1.20k
                }
1672
604
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1673
604
                h_off = 2;
1674
604
            }
1675
4.42k
            if (bw4 == 1) {
1676
2.37k
                const enum Filter2d left_filter_2d =
1677
2.37k
                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
1678
7.11k
                for (int pl = 0; pl < 2; pl++) {
1679
4.74k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + v_off, NULL,
1680
4.74k
                             f->cur.stride[1], bw4, bh4, t->bx - 1,
1681
4.74k
                             t->by, 1 + pl, r[0][t->bx - 1].mv.mv[0],
1682
4.74k
                             &f->refp[r[0][t->bx - 1].ref.ref[0] - 1],
1683
4.74k
                             r[0][t->bx - 1].ref.ref[0] - 1,
1684
4.74k
                             t->frame_thread.pass != 2 ? left_filter_2d :
1685
4.74k
                                 f->frame_thread.b[(t->by * f->b4_stride) + t->bx - 1].filter2d);
1686
4.74k
                    if (res) return res;
1687
4.74k
                }
1688
2.37k
                h_off = 2;
1689
2.37k
            }
1690
4.42k
            if (bh4 == ss_ver) {
1691
2.65k
                const enum Filter2d top_filter_2d =
1692
2.65k
                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
1693
7.96k
                for (int pl = 0; pl < 2; pl++) {
1694
5.31k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off, NULL,
1695
5.31k
                             f->cur.stride[1], bw4, bh4, t->bx, t->by - 1,
1696
5.31k
                             1 + pl, r[-1][t->bx].mv.mv[0],
1697
5.31k
                             &f->refp[r[-1][t->bx].ref.ref[0] - 1],
1698
5.31k
                             r[-1][t->bx].ref.ref[0] - 1,
1699
5.31k
                             t->frame_thread.pass != 2 ? top_filter_2d :
1700
5.31k
                                 f->frame_thread.b[((t->by - 1) * f->b4_stride) + t->bx].filter2d);
1701
5.31k
                    if (res) return res;
1702
5.31k
                }
1703
2.65k
                v_off = 2 * PXSTRIDE(f->cur.stride[1]);
1704
2.65k
            }
1705
13.2k
            for (int pl = 0; pl < 2; pl++) {
1706
8.84k
                res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff + h_off + v_off, NULL, f->cur.stride[1],
1707
8.84k
                         bw4, bh4, t->bx, t->by, 1 + pl, b->mv[0],
1708
8.84k
                         refp, b->ref[0], filter_2d);
1709
8.84k
                if (res) return res;
1710
8.84k
            }
1711
27.2k
        } else {
1712
27.2k
            if (imin(cbw4, cbh4) > 1 &&
1713
13.9k
                ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
1714
13.6k
                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
1715
326
            {
1716
978
                for (int pl = 0; pl < 2; pl++) {
1717
652
                    res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
1718
652
                                      f->cur.stride[1], b_dim, 1 + pl, refp,
1719
652
                                      b->motion_mode == MM_WARP ? &t->warpmv :
1720
652
                                          &f->frame_hdr->gmv[b->ref[0]]);
1721
652
                    if (res) return res;
1722
652
                }
1723
26.8k
            } else {
1724
80.6k
                for (int pl = 0; pl < 2; pl++) {
1725
53.7k
                    res = mc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1726
53.7k
                             NULL, f->cur.stride[1],
1727
53.7k
                             bw4 << (bw4 == ss_hor), bh4 << (bh4 == ss_ver),
1728
53.7k
                             t->bx & ~ss_hor, t->by & ~ss_ver,
1729
53.7k
                             1 + pl, b->mv[0], refp, b->ref[0], filter_2d);
1730
53.7k
                    if (res) return res;
1731
53.7k
                    if (b->motion_mode == MM_OBMC) {
1732
18.9k
                        res = obmc(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff,
1733
18.9k
                                   f->cur.stride[1], b_dim, 1 + pl, bx4, by4, w4, h4);
1734
18.9k
                        if (res) return res;
1735
18.9k
                    }
1736
53.7k
                }
1737
26.8k
            }
1738
27.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
1.30k
                const uint8_t *const ii_mask = II_MASK(chr_layout_idx, bs, b);
1743
1744
3.90k
                for (int pl = 0; pl < 2; pl++) {
1745
2.60k
                    pixel *const tmp = bitfn(t->scratch.interintra);
1746
2.60k
                    pixel *const tl_edge = bitfn(t->scratch.edge) + 32;
1747
2.60k
                    enum IntraPredMode m =
1748
2.60k
                        b->interintra_mode == II_SMOOTH_PRED ?
1749
2.11k
                        SMOOTH_PRED : b->interintra_mode;
1750
2.60k
                    int angle = 0;
1751
2.60k
                    pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1752
2.60k
                    const pixel *top_sb_edge = NULL;
1753
2.60k
                    if (!(t->by & (f->sb_step - 1))) {
1754
756
                        top_sb_edge = f->ipred_edge[pl + 1];
1755
756
                        const int sby = t->by >> f->sb_shift;
1756
756
                        top_sb_edge += f->sb128w * 128 * (sby - 1);
1757
756
                    }
1758
2.60k
                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
1759
2.60k
                                                          (t->bx >> ss_hor) >
1760
2.60k
                                                              (ts->tiling.col_start >> ss_hor),
1761
2.60k
                                                          t->by >> ss_ver,
1762
2.60k
                                                          (t->by >> ss_ver) >
1763
2.60k
                                                              (ts->tiling.row_start >> ss_ver),
1764
2.60k
                                                          ts->tiling.col_end >> ss_hor,
1765
2.60k
                                                          ts->tiling.row_end >> ss_ver,
1766
2.60k
                                                          0, uvdst, f->cur.stride[1],
1767
2.60k
                                                          top_sb_edge, m,
1768
2.60k
                                                          &angle, cbw4, cbh4, 0, tl_edge
1769
2.60k
                                                          HIGHBD_CALL_SUFFIX);
1770
2.60k
                    dsp->ipred.intra_pred[m](tmp, cbw4 * 4 * sizeof(pixel),
1771
2.60k
                                             tl_edge, cbw4 * 4, cbh4 * 4, 0, 0, 0
1772
2.60k
                                             HIGHBD_CALL_SUFFIX);
1773
2.60k
                    dsp->mc.blend(uvdst, f->cur.stride[1], tmp,
1774
2.60k
                                  cbw4 * 4, cbh4 * 4, ii_mask);
1775
2.60k
                }
1776
1.30k
            }
1777
27.2k
        }
1778
1779
44.6k
    skip_inter_chroma_pred: {}
1780
44.6k
        t->tl_4x4_filter = filter_2d;
1781
44.6k
    } else {
1782
4.50k
        const enum Filter2d filter_2d = b->filter2d;
1783
        // Maximum super block size is 128x128
1784
4.50k
        int16_t (*tmp)[128 * 128] = t->scratch.compinter;
1785
4.50k
        int jnt_weight;
1786
4.50k
        uint8_t *const seg_mask = t->scratch.seg_mask;
1787
4.50k
        const uint8_t *mask;
1788
1789
13.5k
        for (int i = 0; i < 2; i++) {
1790
9.00k
            const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1791
1792
9.00k
            if (b->inter_mode == GLOBALMV_GLOBALMV && f->gmv_warp_allowed[b->ref[i]]) {
1793
103
                res = warp_affine(t, NULL, tmp[i], bw4 * 4, b_dim, 0, refp,
1794
103
                                  &f->frame_hdr->gmv[b->ref[i]]);
1795
103
                if (res) return res;
1796
8.90k
            } else {
1797
8.90k
                res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by, 0,
1798
8.90k
                         b->mv[i], refp, b->ref[i], filter_2d);
1799
8.90k
                if (res) return res;
1800
8.90k
            }
1801
9.00k
        }
1802
4.50k
        switch (b->comp_type) {
1803
3.32k
        case COMP_INTER_AVG:
1804
3.32k
            dsp->mc.avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1805
3.32k
                        bw4 * 4, bh4 * 4 HIGHBD_CALL_SUFFIX);
1806
3.32k
            break;
1807
298
        case COMP_INTER_WEIGHTED_AVG:
1808
298
            jnt_weight = f->jnt_weights[b->ref[0]][b->ref[1]];
1809
298
            dsp->mc.w_avg(dst, f->cur.stride[0], tmp[0], tmp[1],
1810
298
                          bw4 * 4, bh4 * 4, jnt_weight HIGHBD_CALL_SUFFIX);
1811
298
            break;
1812
569
        case COMP_INTER_SEG:
1813
569
            dsp->mc.w_mask[chr_layout_idx](dst, f->cur.stride[0],
1814
569
                                           tmp[b->mask_sign], tmp[!b->mask_sign],
1815
569
                                           bw4 * 4, bh4 * 4, seg_mask,
1816
569
                                           b->mask_sign HIGHBD_CALL_SUFFIX);
1817
569
            mask = seg_mask;
1818
569
            break;
1819
313
        case COMP_INTER_WEDGE:
1820
313
            mask = WEDGE_MASK(0, bs, 0, b->wedge_idx);
1821
313
            dsp->mc.mask(dst, f->cur.stride[0],
1822
313
                         tmp[b->mask_sign], tmp[!b->mask_sign],
1823
313
                         bw4 * 4, bh4 * 4, mask HIGHBD_CALL_SUFFIX);
1824
313
            if (has_chroma)
1825
237
                mask = WEDGE_MASK(chr_layout_idx, bs, b->mask_sign, b->wedge_idx);
1826
313
            break;
1827
4.50k
        }
1828
1829
        // chroma
1830
9.45k
        if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1831
18.9k
            for (int i = 0; i < 2; i++) {
1832
12.6k
                const Dav1dThreadPicture *const refp = &f->refp[b->ref[i]];
1833
12.6k
                if (b->inter_mode == GLOBALMV_GLOBALMV &&
1834
1.60k
                    imin(cbw4, cbh4) > 1 && f->gmv_warp_allowed[b->ref[i]])
1835
46
                {
1836
46
                    res = warp_affine(t, NULL, tmp[i], bw4 * 4 >> ss_hor,
1837
46
                                      b_dim, 1 + pl,
1838
46
                                      refp, &f->frame_hdr->gmv[b->ref[i]]);
1839
46
                    if (res) return res;
1840
12.5k
                } else {
1841
12.5k
                    res = mc(t, NULL, tmp[i], 0, bw4, bh4, t->bx, t->by,
1842
12.5k
                             1 + pl, b->mv[i], refp, b->ref[i], filter_2d);
1843
12.5k
                    if (res) return res;
1844
12.5k
                }
1845
12.6k
            }
1846
6.30k
            pixel *const uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff;
1847
6.30k
            switch (b->comp_type) {
1848
4.81k
            case COMP_INTER_AVG:
1849
4.81k
                dsp->mc.avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1850
4.81k
                            bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver
1851
4.81k
                            HIGHBD_CALL_SUFFIX);
1852
4.81k
                break;
1853
216
            case COMP_INTER_WEIGHTED_AVG:
1854
216
                dsp->mc.w_avg(uvdst, f->cur.stride[1], tmp[0], tmp[1],
1855
216
                              bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, jnt_weight
1856
216
                              HIGHBD_CALL_SUFFIX);
1857
216
                break;
1858
474
            case COMP_INTER_WEDGE:
1859
1.27k
            case COMP_INTER_SEG:
1860
1.27k
                dsp->mc.mask(uvdst, f->cur.stride[1],
1861
1.27k
                             tmp[b->mask_sign], tmp[!b->mask_sign],
1862
1.27k
                             bw4 * 4 >> ss_hor, bh4 * 4 >> ss_ver, mask
1863
1.27k
                             HIGHBD_CALL_SUFFIX);
1864
1.27k
                break;
1865
6.30k
            }
1866
6.30k
        }
1867
4.50k
    }
1868
1869
67.8k
    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
67.8k
    const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
1880
1881
67.8k
    if (b->skip) {
1882
        // reset coef contexts
1883
33.1k
        BlockContext *const a = t->a;
1884
33.1k
        dav1d_memset_pow2[b_dim[2]](&a->lcoef[bx4], 0x40);
1885
33.1k
        dav1d_memset_pow2[b_dim[3]](&t->l.lcoef[by4], 0x40);
1886
33.1k
        if (has_chroma) {
1887
25.3k
            dav1d_memset_pow2_fn memset_cw = dav1d_memset_pow2[ulog2(cbw4)];
1888
25.3k
            dav1d_memset_pow2_fn memset_ch = dav1d_memset_pow2[ulog2(cbh4)];
1889
25.3k
            memset_cw(&a->ccoef[0][cbx4], 0x40);
1890
25.3k
            memset_cw(&a->ccoef[1][cbx4], 0x40);
1891
25.3k
            memset_ch(&t->l.ccoef[0][cby4], 0x40);
1892
25.3k
            memset_ch(&t->l.ccoef[1][cby4], 0x40);
1893
25.3k
        }
1894
33.1k
        return 0;
1895
33.1k
    }
1896
1897
34.6k
    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
1898
34.6k
    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
1899
34.6k
    const uint16_t tx_split[2] = { b->tx_split0, b->tx_split1 };
1900
1901
70.0k
    for (int init_y = 0; init_y < bh4; init_y += 16) {
1902
72.2k
        for (int init_x = 0; init_x < bw4; init_x += 16) {
1903
            // coefficient coding & inverse transforms
1904
36.8k
            int y_off = !!init_y, y;
1905
36.8k
            dst += PXSTRIDE(f->cur.stride[0]) * 4 * init_y;
1906
76.9k
            for (y = init_y, t->by += init_y; y < imin(h4, init_y + 16);
1907
40.0k
                 y += ytx->h, y_off++)
1908
40.0k
            {
1909
40.0k
                int x, x_off = !!init_x;
1910
91.0k
                for (x = init_x, t->bx += init_x; x < imin(w4, init_x + 16);
1911
50.9k
                     x += ytx->w, x_off++)
1912
50.9k
                {
1913
50.9k
                    read_coef_tree(t, bs, b, b->max_ytx, 0, tx_split,
1914
50.9k
                                   x_off, y_off, &dst[x * 4]);
1915
50.9k
                    t->bx += ytx->w;
1916
50.9k
                }
1917
40.0k
                dst += PXSTRIDE(f->cur.stride[0]) * 4 * ytx->h;
1918
40.0k
                t->bx -= x;
1919
40.0k
                t->by += ytx->h;
1920
40.0k
            }
1921
36.8k
            dst -= PXSTRIDE(f->cur.stride[0]) * 4 * y;
1922
36.8k
            t->by -= y;
1923
1924
            // chroma coefs and inverse transform
1925
83.6k
            if (has_chroma) for (int pl = 0; pl < 2; pl++) {
1926
55.7k
                pixel *uvdst = ((pixel *) f->cur.data[1 + pl]) + uvdstoff +
1927
55.7k
                    (PXSTRIDE(f->cur.stride[1]) * init_y * 4 >> ss_ver);
1928
55.7k
                for (y = init_y >> ss_ver, t->by += init_y;
1929
117k
                     y < imin(ch4, (init_y + 16) >> ss_ver); y += uvtx->h)
1930
61.2k
                {
1931
61.2k
                    int x;
1932
61.2k
                    for (x = init_x >> ss_hor, t->bx += init_x;
1933
135k
                         x < imin(cw4, (init_x + 16) >> ss_hor); x += uvtx->w)
1934
74.0k
                    {
1935
74.0k
                        coef *cf;
1936
74.0k
                        int eob;
1937
74.0k
                        enum TxfmType txtp;
1938
74.0k
                        if (t->frame_thread.pass) {
1939
74.0k
                            const int p = t->frame_thread.pass & 1;
1940
74.0k
                            const int cbi = *ts->frame_thread[p].cbi++;
1941
74.0k
                            cf = ts->frame_thread[p].cf;
1942
74.0k
                            ts->frame_thread[p].cf += uvtx->w * uvtx->h * 16;
1943
74.0k
                            eob  = cbi >> 5;
1944
74.0k
                            txtp = cbi & 0x1f;
1945
18.4E
                        } else {
1946
18.4E
                            uint8_t cf_ctx;
1947
18.4E
                            cf = bitfn(t->cf);
1948
18.4E
                            txtp = t->scratch.txtp_map[(by4 + (y << ss_ver)) * 32 +
1949
18.4E
                                                        bx4 + (x << ss_hor)];
1950
18.4E
                            eob = decode_coefs(t, &t->a->ccoef[pl][cbx4 + x],
1951
18.4E
                                               &t->l.ccoef[pl][cby4 + y],
1952
18.4E
                                               b->uvtx, bs, b, 0, 1 + pl,
1953
18.4E
                                               cf, &txtp, &cf_ctx);
1954
18.4E
                            if (DEBUG_BLOCK_INFO)
1955
0
                                printf("Post-uv-cf-blk[pl=%d,tx=%d,"
1956
0
                                       "txtp=%d,eob=%d]: r=%d\n",
1957
0
                                       pl, b->uvtx, txtp, eob, ts->msac.rng);
1958
18.4E
                            int ctw = imin(uvtx->w, (f->bw - t->bx + ss_hor) >> ss_hor);
1959
18.4E
                            int cth = imin(uvtx->h, (f->bh - t->by + ss_ver) >> ss_ver);
1960
18.4E
                            dav1d_memset_likely_pow2(&t->a->ccoef[pl][cbx4 + x], cf_ctx, ctw);
1961
18.4E
                            dav1d_memset_likely_pow2(&t->l.ccoef[pl][cby4 + y], cf_ctx, cth);
1962
18.4E
                        }
1963
74.0k
                        if (eob >= 0) {
1964
18.8k
                            if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS)
1965
0
                                coef_dump(cf, uvtx->h * 4, uvtx->w * 4, 3, "dq");
1966
18.8k
                            dsp->itx.itxfm_add[b->uvtx]
1967
18.8k
                                              [txtp](&uvdst[4 * x],
1968
18.8k
                                                     f->cur.stride[1],
1969
18.8k
                                                     cf, eob HIGHBD_CALL_SUFFIX);
1970
18.8k
                            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
18.8k
                        }
1974
74.0k
                        t->bx += uvtx->w << ss_hor;
1975
74.0k
                    }
1976
61.2k
                    uvdst += PXSTRIDE(f->cur.stride[1]) * 4 * uvtx->h;
1977
61.2k
                    t->bx -= x << ss_hor;
1978
61.2k
                    t->by += uvtx->h << ss_ver;
1979
61.2k
                }
1980
55.7k
                t->by -= y << ss_ver;
1981
55.7k
            }
1982
36.8k
        }
1983
35.4k
    }
1984
34.6k
    return 0;
1985
67.8k
}
1986
1987
82.6k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
82.6k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
82.6k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
82.6k
    const int y = sby * f->sb_step * 4;
1994
82.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
82.6k
    pixel *const p[3] = {
1996
82.6k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
82.6k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
82.6k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
82.6k
    };
2000
82.6k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
82.6k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
82.6k
                                        f->lf.start_of_tile_row[sby]);
2003
82.6k
}
dav1d_filter_sbrow_deblock_cols_8bpc
Line
Count
Source
1987
40.0k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
40.0k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
40.0k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
40.0k
    const int y = sby * f->sb_step * 4;
1994
40.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
40.0k
    pixel *const p[3] = {
1996
40.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
40.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
40.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
40.0k
    };
2000
40.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
40.0k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
40.0k
                                        f->lf.start_of_tile_row[sby]);
2003
40.0k
}
dav1d_filter_sbrow_deblock_cols_16bpc
Line
Count
Source
1987
42.5k
void bytefn(dav1d_filter_sbrow_deblock_cols)(Dav1dFrameContext *const f, const int sby) {
1988
42.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK) ||
1989
42.5k
        (!f->frame_hdr->loopfilter.level_y[0] && !f->frame_hdr->loopfilter.level_y[1]))
1990
0
    {
1991
0
        return;
1992
0
    }
1993
42.5k
    const int y = sby * f->sb_step * 4;
1994
42.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
1995
42.5k
    pixel *const p[3] = {
1996
42.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
1997
42.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
1998
42.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
1999
42.5k
    };
2000
42.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2001
42.5k
    bytefn(dav1d_loopfilter_sbrow_cols)(f, p, mask, sby,
2002
42.5k
                                        f->lf.start_of_tile_row[sby]);
2003
42.5k
}
2004
2005
89.0k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
89.0k
    const int y = sby * f->sb_step * 4;
2007
89.0k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
89.0k
    pixel *const p[3] = {
2009
89.0k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
89.0k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
89.0k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
89.0k
    };
2013
89.0k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
89.0k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
89.0k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
82.6k
    {
2017
82.6k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
82.6k
    }
2019
89.0k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
63.8k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
63.8k
    }
2023
89.0k
}
dav1d_filter_sbrow_deblock_rows_8bpc
Line
Count
Source
2005
42.1k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
42.1k
    const int y = sby * f->sb_step * 4;
2007
42.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
42.1k
    pixel *const p[3] = {
2009
42.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
42.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
42.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
42.1k
    };
2013
42.1k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
42.1k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
42.1k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
40.0k
    {
2017
40.0k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
40.0k
    }
2019
42.1k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
26.5k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
26.5k
    }
2023
42.1k
}
dav1d_filter_sbrow_deblock_rows_16bpc
Line
Count
Source
2005
46.9k
void bytefn(dav1d_filter_sbrow_deblock_rows)(Dav1dFrameContext *const f, const int sby) {
2006
46.9k
    const int y = sby * f->sb_step * 4;
2007
46.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2008
46.9k
    pixel *const p[3] = {
2009
46.9k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2010
46.9k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2011
46.9k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2012
46.9k
    };
2013
46.9k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2014
46.9k
    if (f->c->inloop_filters & DAV1D_INLOOPFILTER_DEBLOCK &&
2015
46.9k
        (f->frame_hdr->loopfilter.level_y[0] || f->frame_hdr->loopfilter.level_y[1]))
2016
42.5k
    {
2017
42.5k
        bytefn(dav1d_loopfilter_sbrow_rows)(f, p, mask, sby);
2018
42.5k
    }
2019
46.9k
    if (f->seq_hdr->cdef || f->lf.restore_planes) {
2020
        // Store loop filtered pixels required by CDEF / LR
2021
37.2k
        bytefn(dav1d_copy_lpf)(f, p, sby);
2022
37.2k
    }
2023
46.9k
}
2024
2025
44.5k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
44.5k
    const Dav1dFrameContext *const f = tc->f;
2027
44.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
44.5k
    const int sbsz = f->sb_step;
2029
44.5k
    const int y = sby * sbsz * 4;
2030
44.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
44.5k
    pixel *const p[3] = {
2032
44.5k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
44.5k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
44.5k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
44.5k
    };
2036
44.5k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
44.5k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
44.5k
    const int start = sby * sbsz;
2039
44.5k
    if (sby) {
2040
30.7k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
30.7k
        pixel *p_up[3] = {
2042
30.7k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
30.7k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
30.7k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
30.7k
        };
2046
30.7k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
30.7k
    }
2048
44.5k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
44.5k
    const int end = imin(start + n_blks, f->bh);
2050
44.5k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
44.5k
}
dav1d_filter_sbrow_cdef_8bpc
Line
Count
Source
2025
20.8k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
20.8k
    const Dav1dFrameContext *const f = tc->f;
2027
20.8k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
20.8k
    const int sbsz = f->sb_step;
2029
20.8k
    const int y = sby * sbsz * 4;
2030
20.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
20.8k
    pixel *const p[3] = {
2032
20.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
20.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
20.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
20.8k
    };
2036
20.8k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
20.8k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
20.8k
    const int start = sby * sbsz;
2039
20.8k
    if (sby) {
2040
15.5k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
15.5k
        pixel *p_up[3] = {
2042
15.5k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
15.5k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
15.5k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
15.5k
        };
2046
15.5k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
15.5k
    }
2048
20.8k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
20.8k
    const int end = imin(start + n_blks, f->bh);
2050
20.8k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
20.8k
}
dav1d_filter_sbrow_cdef_16bpc
Line
Count
Source
2025
23.7k
void bytefn(dav1d_filter_sbrow_cdef)(Dav1dTaskContext *const tc, const int sby) {
2026
23.7k
    const Dav1dFrameContext *const f = tc->f;
2027
23.7k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_CDEF)) return;
2028
23.7k
    const int sbsz = f->sb_step;
2029
23.7k
    const int y = sby * sbsz * 4;
2030
23.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2031
23.7k
    pixel *const p[3] = {
2032
23.7k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2033
23.7k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2034
23.7k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2035
23.7k
    };
2036
23.7k
    Av1Filter *prev_mask = f->lf.mask + ((sby - 1) >> !f->seq_hdr->sb128) * f->sb128w;
2037
23.7k
    Av1Filter *mask = f->lf.mask + (sby >> !f->seq_hdr->sb128) * f->sb128w;
2038
23.7k
    const int start = sby * sbsz;
2039
23.7k
    if (sby) {
2040
15.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2041
15.2k
        pixel *p_up[3] = {
2042
15.2k
            p[0] - 8 * PXSTRIDE(f->cur.stride[0]),
2043
15.2k
            p[1] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2044
15.2k
            p[2] - (8 * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2045
15.2k
        };
2046
15.2k
        bytefn(dav1d_cdef_brow)(tc, p_up, prev_mask, start - 2, start, 1, sby);
2047
15.2k
    }
2048
23.7k
    const int n_blks = sbsz - 2 * (sby + 1 < f->sbh);
2049
23.7k
    const int end = imin(start + n_blks, f->bh);
2050
23.7k
    bytefn(dav1d_cdef_brow)(tc, p, mask, start, end, 0, sby);
2051
23.7k
}
2052
2053
17.8k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
17.8k
    const int sbsz = f->sb_step;
2055
17.8k
    const int y = sby * sbsz * 4;
2056
17.8k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
17.8k
    const pixel *const p[3] = {
2058
17.8k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
17.8k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
17.8k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
17.8k
    };
2062
17.8k
    pixel *const sr_p[3] = {
2063
17.8k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
17.8k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
17.8k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
17.8k
    };
2067
17.8k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
55.8k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
37.9k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
37.9k
        const int h_start = 8 * !!sby >> ss_ver;
2071
37.9k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
37.9k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
37.9k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
37.9k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
37.9k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
37.9k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
37.9k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
37.9k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
37.9k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
37.9k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
37.9k
                          imin(img_h, h_end) + h_start, src_w,
2083
37.9k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
37.9k
                          HIGHBD_CALL_SUFFIX);
2085
37.9k
    }
2086
17.8k
}
dav1d_filter_sbrow_resize_8bpc
Line
Count
Source
2053
5.74k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
5.74k
    const int sbsz = f->sb_step;
2055
5.74k
    const int y = sby * sbsz * 4;
2056
5.74k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
5.74k
    const pixel *const p[3] = {
2058
5.74k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
5.74k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
5.74k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
5.74k
    };
2062
5.74k
    pixel *const sr_p[3] = {
2063
5.74k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
5.74k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
5.74k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
5.74k
    };
2067
5.74k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
19.2k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
13.5k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
13.5k
        const int h_start = 8 * !!sby >> ss_ver;
2071
13.5k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
13.5k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
13.5k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
13.5k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
13.5k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
13.5k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
13.5k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
13.5k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
13.5k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
13.5k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
13.5k
                          imin(img_h, h_end) + h_start, src_w,
2083
13.5k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
13.5k
                          HIGHBD_CALL_SUFFIX);
2085
13.5k
    }
2086
5.74k
}
dav1d_filter_sbrow_resize_16bpc
Line
Count
Source
2053
12.1k
void bytefn(dav1d_filter_sbrow_resize)(Dav1dFrameContext *const f, const int sby) {
2054
12.1k
    const int sbsz = f->sb_step;
2055
12.1k
    const int y = sby * sbsz * 4;
2056
12.1k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2057
12.1k
    const pixel *const p[3] = {
2058
12.1k
        f->lf.p[0] + y * PXSTRIDE(f->cur.stride[0]),
2059
12.1k
        f->lf.p[1] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver),
2060
12.1k
        f->lf.p[2] + (y * PXSTRIDE(f->cur.stride[1]) >> ss_ver)
2061
12.1k
    };
2062
12.1k
    pixel *const sr_p[3] = {
2063
12.1k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2064
12.1k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2065
12.1k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2066
12.1k
    };
2067
12.1k
    const int has_chroma = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400;
2068
36.6k
    for (int pl = 0; pl < 1 + 2 * has_chroma; pl++) {
2069
24.4k
        const int ss_ver = pl && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2070
24.4k
        const int h_start = 8 * !!sby >> ss_ver;
2071
24.4k
        const ptrdiff_t dst_stride = f->sr_cur.p.stride[!!pl];
2072
24.4k
        pixel *dst = sr_p[pl] - h_start * PXSTRIDE(dst_stride);
2073
24.4k
        const ptrdiff_t src_stride = f->cur.stride[!!pl];
2074
24.4k
        const pixel *src = p[pl] - h_start * PXSTRIDE(src_stride);
2075
24.4k
        const int h_end = 4 * (sbsz - 2 * (sby + 1 < f->sbh)) >> ss_ver;
2076
24.4k
        const int ss_hor = pl && f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2077
24.4k
        const int dst_w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
2078
24.4k
        const int src_w = (4 * f->bw + ss_hor) >> ss_hor;
2079
24.4k
        const int img_h = (f->cur.p.h - sbsz * 4 * sby + ss_ver) >> ss_ver;
2080
2081
24.4k
        f->dsp->mc.resize(dst, dst_stride, src, src_stride, dst_w,
2082
24.4k
                          imin(img_h, h_end) + h_start, src_w,
2083
24.4k
                          f->resize_step[!!pl], f->resize_start[!!pl]
2084
24.4k
                          HIGHBD_CALL_SUFFIX);
2085
24.4k
    }
2086
12.1k
}
2087
2088
44.4k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
44.4k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
44.4k
    const int y = sby * f->sb_step * 4;
2091
44.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
44.4k
    pixel *const sr_p[3] = {
2093
44.4k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
44.4k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
44.4k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
44.4k
    };
2097
44.4k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
44.4k
}
dav1d_filter_sbrow_lr_8bpc
Line
Count
Source
2088
17.9k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
17.9k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
17.9k
    const int y = sby * f->sb_step * 4;
2091
17.9k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
17.9k
    pixel *const sr_p[3] = {
2093
17.9k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
17.9k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
17.9k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
17.9k
    };
2097
17.9k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
17.9k
}
dav1d_filter_sbrow_lr_16bpc
Line
Count
Source
2088
26.5k
void bytefn(dav1d_filter_sbrow_lr)(Dav1dFrameContext *const f, const int sby) {
2089
26.5k
    if (!(f->c->inloop_filters & DAV1D_INLOOPFILTER_RESTORATION)) return;
2090
26.5k
    const int y = sby * f->sb_step * 4;
2091
26.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2092
26.5k
    pixel *const sr_p[3] = {
2093
26.5k
        f->lf.sr_p[0] + y * PXSTRIDE(f->sr_cur.p.stride[0]),
2094
26.5k
        f->lf.sr_p[1] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver),
2095
26.5k
        f->lf.sr_p[2] + (y * PXSTRIDE(f->sr_cur.p.stride[1]) >> ss_ver)
2096
26.5k
    };
2097
26.5k
    bytefn(dav1d_lr_sbrow)(f, sr_p, sby);
2098
26.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
98.4k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
98.4k
    const Dav1dFrameContext *const f = t->f;
2113
98.4k
    Dav1dTileState *const ts = t->ts;
2114
98.4k
    const int sby = t->by >> f->sb_shift;
2115
98.4k
    const int sby_off = f->sb128w * 128 * sby;
2116
98.4k
    const int x_off = ts->tiling.col_start;
2117
2118
98.4k
    const pixel *const y =
2119
98.4k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
98.4k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
98.4k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
98.4k
               4 * (ts->tiling.col_end - x_off));
2123
2124
98.4k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
71.1k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
71.1k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
71.1k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
71.1k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
213k
        for (int pl = 1; pl <= 2; pl++)
2131
142k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
65.7k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
65.7k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
71.1k
    }
2135
98.4k
}
dav1d_backup_ipred_edge_8bpc
Line
Count
Source
2111
45.6k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
45.6k
    const Dav1dFrameContext *const f = t->f;
2113
45.6k
    Dav1dTileState *const ts = t->ts;
2114
45.6k
    const int sby = t->by >> f->sb_shift;
2115
45.6k
    const int sby_off = f->sb128w * 128 * sby;
2116
45.6k
    const int x_off = ts->tiling.col_start;
2117
2118
45.6k
    const pixel *const y =
2119
45.6k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
45.6k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
45.6k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
45.6k
               4 * (ts->tiling.col_end - x_off));
2123
2124
45.6k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
32.8k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
32.8k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
32.8k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
32.8k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
98.6k
        for (int pl = 1; pl <= 2; pl++)
2131
65.7k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
65.7k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
65.7k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
32.8k
    }
2135
45.6k
}
dav1d_backup_ipred_edge_16bpc
Line
Count
Source
2111
52.8k
void bytefn(dav1d_backup_ipred_edge)(Dav1dTaskContext *const t) {
2112
52.8k
    const Dav1dFrameContext *const f = t->f;
2113
52.8k
    Dav1dTileState *const ts = t->ts;
2114
52.8k
    const int sby = t->by >> f->sb_shift;
2115
52.8k
    const int sby_off = f->sb128w * 128 * sby;
2116
52.8k
    const int x_off = ts->tiling.col_start;
2117
2118
52.8k
    const pixel *const y =
2119
52.8k
        ((const pixel *) f->cur.data[0]) + x_off * 4 +
2120
52.8k
                    ((t->by + f->sb_step) * 4 - 1) * PXSTRIDE(f->cur.stride[0]);
2121
52.8k
    pixel_copy(&f->ipred_edge[0][sby_off + x_off * 4], y,
2122
52.8k
               4 * (ts->tiling.col_end - x_off));
2123
2124
52.8k
    if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
2125
38.2k
        const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2126
38.2k
        const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2127
2128
38.2k
        const ptrdiff_t uv_off = (x_off * 4 >> ss_hor) +
2129
38.2k
            (((t->by + f->sb_step) * 4 >> ss_ver) - 1) * PXSTRIDE(f->cur.stride[1]);
2130
114k
        for (int pl = 1; pl <= 2; pl++)
2131
76.5k
            pixel_copy(&f->ipred_edge[pl][sby_off + (x_off * 4 >> ss_hor)],
2132
38.2k
                       &((const pixel *) f->cur.data[pl])[uv_off],
2133
38.2k
                       4 * (ts->tiling.col_end - x_off) >> ss_hor);
2134
38.2k
    }
2135
52.8k
}
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
12.7k
{
2142
12.7k
    const Dav1dFrameContext *const f = t->f;
2143
12.7k
    pixel *const pal = t->frame_thread.pass ?
2144
12.7k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
12.7k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
12.7k
        bytefn(t->scratch.pal)[0];
2147
58.5k
    for (int x = 0; x < bw4; x++)
2148
45.8k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
51.3k
    for (int y = 0; y < bh4; y++)
2150
38.5k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
12.7k
}
dav1d_copy_pal_block_y_8bpc
Line
Count
Source
2141
7.06k
{
2142
7.06k
    const Dav1dFrameContext *const f = t->f;
2143
7.06k
    pixel *const pal = t->frame_thread.pass ?
2144
7.06k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
7.06k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
7.06k
        bytefn(t->scratch.pal)[0];
2147
32.4k
    for (int x = 0; x < bw4; x++)
2148
25.3k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
27.2k
    for (int y = 0; y < bh4; y++)
2150
20.2k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
7.06k
}
dav1d_copy_pal_block_y_16bpc
Line
Count
Source
2141
5.70k
{
2142
5.70k
    const Dav1dFrameContext *const f = t->f;
2143
5.70k
    pixel *const pal = t->frame_thread.pass ?
2144
5.70k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2145
5.70k
                            ((t->bx >> 1) + (t->by & 1))][0] :
2146
5.70k
        bytefn(t->scratch.pal)[0];
2147
26.1k
    for (int x = 0; x < bw4; x++)
2148
20.4k
        memcpy(bytefn(t->al_pal)[0][bx4 + x][0], pal, 8 * sizeof(pixel));
2149
24.0k
    for (int y = 0; y < bh4; y++)
2150
18.3k
        memcpy(bytefn(t->al_pal)[1][by4 + y][0], pal, 8 * sizeof(pixel));
2151
5.70k
}
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.40k
{
2158
3.40k
    const Dav1dFrameContext *const f = t->f;
2159
3.40k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
3.40k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
3.40k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
3.40k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
10.2k
    for (int pl = 1; pl <= 2; pl++) {
2165
35.9k
        for (int x = 0; x < bw4; x++)
2166
29.1k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
31.5k
        for (int y = 0; y < bh4; y++)
2168
24.7k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
6.81k
    }
2170
3.40k
}
dav1d_copy_pal_block_uv_8bpc
Line
Count
Source
2157
1.90k
{
2158
1.90k
    const Dav1dFrameContext *const f = t->f;
2159
1.90k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
1.90k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
1.90k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
1.90k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
5.70k
    for (int pl = 1; pl <= 2; pl++) {
2165
20.0k
        for (int x = 0; x < bw4; x++)
2166
16.2k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
17.7k
        for (int y = 0; y < bh4; y++)
2168
13.8k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
3.80k
    }
2170
1.90k
}
dav1d_copy_pal_block_uv_16bpc
Line
Count
Source
2157
1.50k
{
2158
1.50k
    const Dav1dFrameContext *const f = t->f;
2159
1.50k
    const pixel (*const pal)[8] = t->frame_thread.pass ?
2160
1.50k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2161
1.50k
                            ((t->bx >> 1) + (t->by & 1))] :
2162
1.50k
        bytefn(t->scratch.pal);
2163
    // see aomedia bug 2183 for why we use luma coordinates here
2164
4.51k
    for (int pl = 1; pl <= 2; pl++) {
2165
15.8k
        for (int x = 0; x < bw4; x++)
2166
12.8k
            memcpy(bytefn(t->al_pal)[0][bx4 + x][pl], pal[pl], 8 * sizeof(pixel));
2167
13.8k
        for (int y = 0; y < bh4; y++)
2168
10.8k
            memcpy(bytefn(t->al_pal)[1][by4 + y][pl], pal[pl], 8 * sizeof(pixel));
2169
3.01k
    }
2170
1.50k
}
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
16.1k
{
2176
16.1k
    Dav1dTileState *const ts = t->ts;
2177
16.1k
    const Dav1dFrameContext *const f = t->f;
2178
16.1k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
16.1k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
16.1k
    pixel cache[16], used_cache[8];
2181
16.1k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
16.1k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
16.1k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
16.1k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
16.1k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
26.5k
    while (l_cache && a_cache) {
2190
10.4k
        if (*l < *a) {
2191
3.93k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
3.89k
                cache[n_cache++] = *l;
2193
3.93k
            l++;
2194
3.93k
            l_cache--;
2195
6.47k
        } else {
2196
6.47k
            if (*a == *l) {
2197
2.65k
                l++;
2198
2.65k
                l_cache--;
2199
2.65k
            }
2200
6.47k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
6.24k
                cache[n_cache++] = *a;
2202
6.47k
            a++;
2203
6.47k
            a_cache--;
2204
6.47k
        }
2205
10.4k
    }
2206
16.1k
    if (l_cache) {
2207
18.9k
        do {
2208
18.9k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
15.6k
                cache[n_cache++] = *l;
2210
18.9k
            l++;
2211
18.9k
        } while (--l_cache > 0);
2212
11.5k
    } else if (a_cache) {
2213
15.8k
        do {
2214
15.8k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
12.7k
                cache[n_cache++] = *a;
2216
15.8k
            a++;
2217
15.8k
        } while (--a_cache > 0);
2218
3.79k
    }
2219
2220
    // find reused cache entries
2221
16.1k
    int i = 0;
2222
50.3k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
34.2k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
17.0k
            used_cache[i++] = cache[n];
2225
16.1k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
16.1k
    pixel *const pal = t->frame_thread.pass ?
2229
16.1k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
16.1k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
16.1k
        bytefn(t->scratch.pal)[pl];
2232
16.1k
    if (i < pal_sz) {
2233
14.0k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
14.0k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
14.0k
        if (i < pal_sz) {
2237
12.6k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
12.6k
            const int max = (1 << bpc) - 1;
2239
2240
29.8k
            do {
2241
29.8k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
29.8k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
29.8k
                if (prev + !pl >= max) {
2244
16.3k
                    for (; i < pal_sz; i++)
2245
10.6k
                        pal[i] = max;
2246
5.68k
                    break;
2247
5.68k
                }
2248
24.1k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
24.1k
            } while (i < pal_sz);
2250
12.6k
        }
2251
2252
        // merge cache+new entries
2253
14.0k
        int n = 0, m = n_used_cache;
2254
79.8k
        for (i = 0; i < pal_sz; i++) {
2255
65.7k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
11.2k
                pal[i] = used_cache[n++];
2257
54.5k
            } else {
2258
54.5k
                assert(m < pal_sz);
2259
54.5k
                pal[i] = pal[m++];
2260
54.5k
            }
2261
65.7k
        }
2262
14.0k
    } else {
2263
2.13k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
2.13k
    }
2265
2266
16.1k
    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
16.1k
}
dav1d_read_pal_plane_8bpc
Line
Count
Source
2175
8.97k
{
2176
8.97k
    Dav1dTileState *const ts = t->ts;
2177
8.97k
    const Dav1dFrameContext *const f = t->f;
2178
8.97k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
8.97k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
8.97k
    pixel cache[16], used_cache[8];
2181
8.97k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
8.97k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
8.97k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
8.97k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
8.97k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
15.3k
    while (l_cache && a_cache) {
2190
6.36k
        if (*l < *a) {
2191
2.36k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
2.34k
                cache[n_cache++] = *l;
2193
2.36k
            l++;
2194
2.36k
            l_cache--;
2195
3.99k
        } else {
2196
3.99k
            if (*a == *l) {
2197
1.64k
                l++;
2198
1.64k
                l_cache--;
2199
1.64k
            }
2200
3.99k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
3.84k
                cache[n_cache++] = *a;
2202
3.99k
            a++;
2203
3.99k
            a_cache--;
2204
3.99k
        }
2205
6.36k
    }
2206
8.97k
    if (l_cache) {
2207
10.9k
        do {
2208
10.9k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
8.90k
                cache[n_cache++] = *l;
2210
10.9k
            l++;
2211
10.9k
        } while (--l_cache > 0);
2212
6.33k
    } else if (a_cache) {
2213
8.73k
        do {
2214
8.73k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
7.09k
                cache[n_cache++] = *a;
2216
8.73k
            a++;
2217
8.73k
        } while (--a_cache > 0);
2218
2.13k
    }
2219
2220
    // find reused cache entries
2221
8.97k
    int i = 0;
2222
28.5k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
19.5k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
9.87k
            used_cache[i++] = cache[n];
2225
8.97k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
8.97k
    pixel *const pal = t->frame_thread.pass ?
2229
8.97k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
8.97k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
8.97k
        bytefn(t->scratch.pal)[pl];
2232
8.97k
    if (i < pal_sz) {
2233
7.73k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
7.73k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
7.73k
        if (i < pal_sz) {
2237
6.96k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
6.96k
            const int max = (1 << bpc) - 1;
2239
2240
16.2k
            do {
2241
16.2k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
16.2k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
16.2k
                if (prev + !pl >= max) {
2244
9.30k
                    for (; i < pal_sz; i++)
2245
6.05k
                        pal[i] = max;
2246
3.25k
                    break;
2247
3.25k
                }
2248
12.9k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
12.9k
            } while (i < pal_sz);
2250
6.96k
        }
2251
2252
        // merge cache+new entries
2253
7.73k
        int n = 0, m = n_used_cache;
2254
44.3k
        for (i = 0; i < pal_sz; i++) {
2255
36.5k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
6.57k
                pal[i] = used_cache[n++];
2257
30.0k
            } else {
2258
30.0k
                assert(m < pal_sz);
2259
30.0k
                pal[i] = pal[m++];
2260
30.0k
            }
2261
36.5k
        }
2262
7.73k
    } else {
2263
1.24k
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
1.24k
    }
2265
2266
8.97k
    if (DEBUG_BLOCK_INFO) {
2267
0
        printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
2268
0
               pl, pal_sz, n_cache, n_used_cache, ts->msac.rng);
2269
0
        for (int n = 0; n < n_cache; n++)
2270
0
            printf("%c%02x", n ? ' ' : '[', cache[n]);
2271
0
        printf("%s, pal=", n_cache ? "]" : "[]");
2272
0
        for (int n = 0; n < pal_sz; n++)
2273
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2274
0
        printf("]\n");
2275
0
    }
2276
8.97k
}
dav1d_read_pal_plane_16bpc
Line
Count
Source
2175
7.20k
{
2176
7.20k
    Dav1dTileState *const ts = t->ts;
2177
7.20k
    const Dav1dFrameContext *const f = t->f;
2178
7.20k
    const int pal_sz = b->pal_sz[pl] = dav1d_msac_decode_symbol_adapt8(&ts->msac,
2179
7.20k
                                           ts->cdf.m.pal_sz[pl][sz_ctx], 6) + 2;
2180
7.20k
    pixel cache[16], used_cache[8];
2181
7.20k
    int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
2182
7.20k
    int n_cache = 0;
2183
    // don't reuse above palette outside SB64 boundaries
2184
7.20k
    int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
2185
7.20k
    const pixel *l = bytefn(t->al_pal)[1][by4][pl];
2186
7.20k
    const pixel *a = bytefn(t->al_pal)[0][bx4][pl];
2187
2188
    // fill/sort cache
2189
11.2k
    while (l_cache && a_cache) {
2190
4.04k
        if (*l < *a) {
2191
1.56k
            if (!n_cache || cache[n_cache - 1] != *l)
2192
1.55k
                cache[n_cache++] = *l;
2193
1.56k
            l++;
2194
1.56k
            l_cache--;
2195
2.48k
        } else {
2196
2.48k
            if (*a == *l) {
2197
1.01k
                l++;
2198
1.01k
                l_cache--;
2199
1.01k
            }
2200
2.48k
            if (!n_cache || cache[n_cache - 1] != *a)
2201
2.39k
                cache[n_cache++] = *a;
2202
2.48k
            a++;
2203
2.48k
            a_cache--;
2204
2.48k
        }
2205
4.04k
    }
2206
7.20k
    if (l_cache) {
2207
8.01k
        do {
2208
8.01k
            if (!n_cache || cache[n_cache - 1] != *l)
2209
6.70k
                cache[n_cache++] = *l;
2210
8.01k
            l++;
2211
8.01k
        } while (--l_cache > 0);
2212
5.25k
    } else if (a_cache) {
2213
7.07k
        do {
2214
7.07k
            if (!n_cache || cache[n_cache - 1] != *a)
2215
5.69k
                cache[n_cache++] = *a;
2216
7.07k
            a++;
2217
7.07k
        } while (--a_cache > 0);
2218
1.65k
    }
2219
2220
    // find reused cache entries
2221
7.20k
    int i = 0;
2222
21.8k
    for (int n = 0; n < n_cache && i < pal_sz; n++)
2223
14.6k
        if (dav1d_msac_decode_bool_equi(&ts->msac))
2224
7.14k
            used_cache[i++] = cache[n];
2225
7.20k
    const int n_used_cache = i;
2226
2227
    // parse new entries
2228
7.20k
    pixel *const pal = t->frame_thread.pass ?
2229
7.20k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2230
7.20k
                            ((t->bx >> 1) + (t->by & 1))][pl] :
2231
7.20k
        bytefn(t->scratch.pal)[pl];
2232
7.20k
    if (i < pal_sz) {
2233
6.30k
        const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2234
6.30k
        int prev = pal[i++] = dav1d_msac_decode_bools(&ts->msac, bpc);
2235
2236
6.30k
        if (i < pal_sz) {
2237
5.67k
            int bits = bpc - 3 + dav1d_msac_decode_bools(&ts->msac, 2);
2238
5.67k
            const int max = (1 << bpc) - 1;
2239
2240
13.6k
            do {
2241
13.6k
                const int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2242
13.6k
                prev = pal[i++] = imin(prev + delta + !pl, max);
2243
13.6k
                if (prev + !pl >= max) {
2244
6.99k
                    for (; i < pal_sz; i++)
2245
4.56k
                        pal[i] = max;
2246
2.43k
                    break;
2247
2.43k
                }
2248
11.1k
                bits = imin(bits, 1 + ulog2(max - prev - !pl));
2249
11.1k
            } while (i < pal_sz);
2250
5.67k
        }
2251
2252
        // merge cache+new entries
2253
6.30k
        int n = 0, m = n_used_cache;
2254
35.4k
        for (i = 0; i < pal_sz; i++) {
2255
29.1k
            if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
2256
4.68k
                pal[i] = used_cache[n++];
2257
24.4k
            } else {
2258
24.4k
                assert(m < pal_sz);
2259
24.4k
                pal[i] = pal[m++];
2260
24.4k
            }
2261
29.1k
        }
2262
6.30k
    } else {
2263
896
        memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
2264
896
    }
2265
2266
7.20k
    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.20k
}
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.40k
{
2281
3.40k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
3.40k
    Dav1dTileState *const ts = t->ts;
2285
3.40k
    const Dav1dFrameContext *const f = t->f;
2286
3.40k
    pixel *const pal = t->frame_thread.pass ?
2287
3.40k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
3.40k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
3.40k
        bytefn(t->scratch.pal)[2];
2290
3.40k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
3.40k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
1.76k
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
1.76k
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
1.76k
        const int max = (1 << bpc) - 1;
2295
7.06k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
5.30k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
5.30k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
5.30k
            prev = pal[i] = (prev + delta) & max;
2299
5.30k
        }
2300
1.76k
    } else {
2301
8.23k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
6.59k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
1.64k
    }
2304
3.40k
    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.40k
}
dav1d_read_pal_uv_8bpc
Line
Count
Source
2280
1.90k
{
2281
1.90k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
1.90k
    Dav1dTileState *const ts = t->ts;
2285
1.90k
    const Dav1dFrameContext *const f = t->f;
2286
1.90k
    pixel *const pal = t->frame_thread.pass ?
2287
1.90k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
1.90k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
1.90k
        bytefn(t->scratch.pal)[2];
2290
1.90k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
1.90k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
986
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
986
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
986
        const int max = (1 << bpc) - 1;
2295
3.95k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
2.97k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
2.97k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
2.97k
            prev = pal[i] = (prev + delta) & max;
2299
2.97k
        }
2300
986
    } else {
2301
4.60k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
3.68k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
917
    }
2304
1.90k
    if (DEBUG_BLOCK_INFO) {
2305
0
        printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
2306
0
        for (int n = 0; n < b->pal_sz[1]; n++)
2307
0
            printf("%c%02x", n ? ' ' : '[', pal[n]);
2308
0
        printf("]\n");
2309
0
    }
2310
1.90k
}
dav1d_read_pal_uv_16bpc
Line
Count
Source
2280
1.50k
{
2281
1.50k
    bytefn(dav1d_read_pal_plane)(t, b, 1, sz_ctx, bx4, by4);
2282
2283
    // V pal coding
2284
1.50k
    Dav1dTileState *const ts = t->ts;
2285
1.50k
    const Dav1dFrameContext *const f = t->f;
2286
1.50k
    pixel *const pal = t->frame_thread.pass ?
2287
1.50k
        f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
2288
1.50k
                            ((t->bx >> 1) + (t->by & 1))][2] :
2289
1.50k
        bytefn(t->scratch.pal)[2];
2290
1.50k
    const int bpc = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
2291
1.50k
    if (dav1d_msac_decode_bool_equi(&ts->msac)) {
2292
779
        const int bits = bpc - 4 + dav1d_msac_decode_bools(&ts->msac, 2);
2293
779
        int prev = pal[0] = dav1d_msac_decode_bools(&ts->msac, bpc);
2294
779
        const int max = (1 << bpc) - 1;
2295
3.10k
        for (int i = 1; i < b->pal_sz[1]; i++) {
2296
2.32k
            int delta = dav1d_msac_decode_bools(&ts->msac, bits);
2297
2.32k
            if (delta && dav1d_msac_decode_bool_equi(&ts->msac)) delta = -delta;
2298
2.32k
            prev = pal[i] = (prev + delta) & max;
2299
2.32k
        }
2300
779
    } else {
2301
3.63k
        for (int i = 0; i < b->pal_sz[1]; i++)
2302
2.90k
            pal[i] = dav1d_msac_decode_bools(&ts->msac, bpc);
2303
726
    }
2304
1.50k
    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.50k
}